使用gradle構建項目
1蠢络、在build.gradle文件中增加以下內容
apply plugin:'war'
在dependencies區(qū)塊中增加
compilegroup:'org.slf4j',name:'slf4j-api',version:'1.7.21'
providedRuntime'org.springframework.boot:spring-boot-starter-tomcat'
2、啟動文件要實現(xiàn)WebApplicationInitializer接口
@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer implements WebApplicationInitializer {}
3冬阳、在webapp目錄下增加WEB-INF/weblogic.xml
此處有幾點需要特別關注的問題
1姑躲、你編寫的啟動文件棉钧,如我這里提到的MyApplication文件恨统,不能放在com包下怪蔑,如果放在com包下一定要增加@ComponentScan(basePackages ="com.test")注解娩践,就是掃描路徑一定不能從com包開始活翩,不然發(fā)布程序會有沖突,導致發(fā)布不成功翻伺。
2材泄、程序發(fā)布時會提示需要jersey-spring包,需要在build.gradle文件中增加compilegroup:'com.sun.jersey.contribs',name:'jersey-spring',version:'1.19'
3吨岭、打包的war文件中l(wèi)ib包中會有一個log4j-slf4j-impl-2.7.jar包拉宗,這個包和org.slf4j包沖突,需要刪除辣辫。
參考文檔:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html