1、修改Application类,复写configure方法
@SpringBootApplication
public class SpringwarApplication
extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringwarApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringwarApplication.class, args);
}
}
2、修改pom.xml
<packaging>war</packaging>
# 省略
<dependencies>
<!-- 略过-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- 略过-->
</dependencies>
3、打包
mvn clean package
将war包直接复制到tomcat目录的webapps下
4、访问服务
比如,war包名称为springwar-0.0.1-SNAPSHOT.war,原来debug时的访问的url为 http://localhost:8080/index ,
那么现在我们要访问的服务为http://localhost:8080/springwar-0.0.1-SNAPSHOT/index
5、tomcat的启动
下载tomcat,我用的是8.5的版本,下载后解压进入bin文件夹
./catalina.sh start