1. 程式人生 > >關於springboot 打war包 部署tomcat 無法啟動報錯的問題

關於springboot 打war包 部署tomcat 無法啟動報錯的問題

springboot 預設是通常是打包成jar的,裡面會內建一個tomcat容器
有時候我們需要使用以前打成war包的方式部署到對應的tomcat中,
具體springboot 怎麼從jar改成war的打包方式我就不細說了,百度一大把

  • 基本就是pom加一個spring-boot-starter-tomcat 的dependency scope為provided
  • packaging由jar改為war
  • 增加一個類 繼承 SpringBootServletInitializer 複寫configure 返回application.sources(原先主函式那個類.class);

clean package -Dmaven.test.skip=true 打包後,放到tomcat6 7 8各種報錯
很可能出問題的原因是springboot內建tomcat的版本和你實際部署到的tomcat不一致,放到正確的對應版本的tomcat下就解決了


檢視springboot 內建tomcat版本的方法
參考 https://www.jb51.net/article/122547.htm
檢視pom

<parent> 
 <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-parent</artifactId> 
 <version>1.5.6.RELEASE</version> 
</parent>

這塊配置就是Spring Boot父級依賴,有了這個,當前的專案就是Spring Boot專案了,
spring-boot-starter-parent是一個特殊的starter,它用來提供相關的Maven預設依賴,
使用它之後,常用的包依賴可以省去version標籤。關於Spring Boot提供了哪些jar包的依賴,
可檢視C:\Users\使用者.m2\repository\org\springframework\boot\spring-boot-dependencies\1.5.1.RELEASE\spring-boot-dependencies-1.5.1.RELEASE.pom
開啟這個pom檔案,搜尋“tomcat.version” 會找到對應tomcat版本

ps:tomcat 8.0 和tomcat 8.5 還是有區別的 ,本來我一直用8.0.x的版本 ,但是現在springboot的內建版本卻是8.5.x的 ,放到8.0是報錯的,必須8.5才行……

ps2: war包部署到tomcat的專案訪問要加上專案名