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>
本文介绍了如何在SpringBoot项目中使用`spring-boot-starter-tomcat`依赖、移除`spring-boot-maven-plugin`并添加`maven-war-plugin`,以及在pom.xml中设置打包和在Tomcat服务器配置中修改默认访问路径,确保SpringBoot应用部署到Tomcat正确运行。

被折叠的 条评论
为什么被折叠?



