將springboot項目發布到獨立的tomcat中運行

來源:互聯網
上載者:User

標籤:provided   war包   span   class   ring   alt   運行   技術分享   root   

在開發階段我們推薦使用內嵌的tomcat進行開發,因為這樣會方便很多,但是到產生環境,我希望在獨立的tomcat容器中運行,因為我們需要對tomcat做額外的最佳化,這時我們需要將工程打包成war包發進行發布。

1.1. 工程的打包方式為war

 

 

1.2. 將spring-boot-starter-tomcat的範圍設定為provided

設定為provided是在打包時會將該包排除,因為要放到獨立的tomcat中運行,是不需要的。

1 <dependency>2 3         <groupId>org.springframework.boot</groupId>4 5         <artifactId>spring-boot-starter-tomcat</artifactId>6 7         <scope>provided</scope>8 9       </dependency>
1.3. 修改代碼,設定啟動配置

需要整合SpringBootServletInitializer,然後重寫configure,將Spring Boot的入口類設定進去。

 

 

1.4. 打war包

 

 

 

打包成功:

 

 

1.5. 部署到tomcat

解壓apache-tomcat-7.0.57.tar.gz,將war包解壓到webapps下的ROOT目錄中,啟動:

 

完美!

 

將springboot項目發布到獨立的tomcat中運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.