springboot(十五)打war包部署到Tomcat下
阿新 • • 發佈:2019-01-03
1、去掉spring-boot-starter-web內建的Tomcat
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
2、修改打包型別
<packaging>war</packaging>
3、因為要在本地啟動,所有新增Tomcatjar包,將scope設定為provided,這樣在打war包的時候不會包含這個jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
4、修改啟動檔案Application繼承SpringBootServletInitializer
@SpringBootApplication
public class SpringbootApplication extends SpringBootServletInitializer {
5、打包
按照從上到下點一遍,在target下找到war包,放到Tomcat的webapps下,啟動Tomcat,然後訪問localhost:埠號/war名稱/介面,如圖: