一、生成war包
java
1)修改POM文件,將打包類型改成war:<packaging>war</packaging>web
<packaging>war</packaging>
(2)添加spring-boot-starter-tomcat依賴,scope設置爲providedspring
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
(3)註冊啓動類tomcat
建立ServletInitializer.java,繼承SpringBootServletInitializer ,覆蓋configure(),把啓動類Application註冊進去。外部web應用服務器構建Web Application Context的時候,會把啓動類添加進去。服務器
public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(BootdemoApplication.class); } }
(4)經過IDEA的Maven工具生成,點擊run as ---maven install,生成war,能夠直接拷到tomcat的webapps目錄下,啓動Tomcat便可。app
注意同一端口號的多個項目部署時,在tomcat/config/server.xml中添加,如:webapp
<Context path="/route" reloadable="true" docBase="/home/develop/tomcat-7.0.54/webapps"/> <Context path="/route2" reloadable="true" docBase="/home/develop/tomcat-7.0.54/webapps"/>
經過訪問:http://127.0.0.1:8080/route http://127.0.0.1:8080/route2 對應各子的項目maven