项目需要工程能发布rest接口,我选择了改造成springboot工程方式,步骤如下:
1、入口类继承 SpringBootServletInitializer,代码如下
@SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
2、pom中增加新的依赖,如果已经依赖了其他的parent 可以再对应的parent中尝试添加spring-boot-starter-parent。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> </parent>
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> </dependency> <dependencies>
3、启动的时候报错了 If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory,原因是使用的 logback和 slf4j-log4j12 core冲突了排除 slf4j-log4j12后可以重新启动