1. 在pom.xml中加入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
2. 在pom.xml中加入 去掉 spring-boot-maven-plugin 加入 maven-war-plugin
<!--
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
3. 在pom.xml中加入 还需要在project标签下加入
<packaging>war</packaging>
4. 在Application启动类中修改
需要继承SpringBootServletInitializer类 extends SpringBootServletInitializer{
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SecurityApplication.class);
}
5. 修改tomcat的默认访问路径
打开tomcat文件夹下的conf,修改server.xml文件,如下:
切记!切记!切记! path="/" 里面必须加 /
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/" docBase="D:\apache-tomcat-8.0.52\webapps\abc"> </Context>
</Host>