SpringBoot版本:2.0.1.RELEASE
WebLogic版本:Weblogic 12c
本文为测试SpringBoot项目部署在Weblogic服务器上的测试项目。不牵扯到任何的业务逻辑。可以直接将本文重点标注的几个点移至您现有的项目。
SpringBoot项目的pom.xml文件
其中需要添加的依赖为:
org.springframework.boot
spring-boot-legacy
2.0.0.RELEASE
org.springframework.boot
spring-boot-starter-tomcat
provided
打成war包文件:war
完整文件如下:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE
com.example
demo
0.0.1-SNAPSHOT
demo
Springboot project run on weblogic.
war
1.8
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-legacy
2.0.0.RELEASE
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-maven-plugin
添加web.xml和weblogic.xml文件
在main目录下创建webapp目录,和java、resources同级。
在webapp目录下添加WEB-INF目录,在WEB-INF目录下创建web.xml和weblogic.xml文件。
web.xml和weblogic.xml文件内容如下:
web.xml,其中com.example.demo.DemoApplication为你项目的启动类文件的目录。
contextConfigLocation
com.example.demo.DemoApplication
org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
contextAttribute
org.springframework.web.context.WebApplicationContext.ROOT
1
appServlet
/
weblogic.xml,其中/demo为项目启动后的访问路径。如果不需要,直接改为/即可
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">
org.slf4j
javax.validation.*
org.hibernate.*
javax.el.*
org.springframework.*
/demo
项目启动类:DemoApplication.java
注意将启动类继承SpringBootServletInitializer, 实现WebApplicationInitializer
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/test")
public String test(){
return "test";
}
}
以上项目配置完成,执行mvn clean package打成war文件。可以直接使用idea的maven打包。
部署项目到weblogic
详细步骤如下图:
显示部署成功后,在浏览器输入地址访问:http://192.168.2.10:7001/demo/test
系统测试
显示结果如下图:
本文到此结束了,后续文章会陆续更新,文档会同步在CSDN和GitHub保持同步更新。
点个关注再走呗~~~
本文地址:https://blog.csdn.net/qq_34988304/article/details/107083786
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!