1.配置pom.xml文件 <packaging>war</packaging> <!-- web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- 移除嵌入式tomcat插件 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> 2.配置StartApplication import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; import com.xxxxx.StartApplication; @SpringBootApplication public class StartApplication extends SpringBootServletInitializer{ //配置打包后可以用tomcat下使用 @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(StartApplication.class); } public static void main(String[] args) { SpringApplication.run(StartApplication.class, args); } } 3.修改tomcat配置文件server.xml
找到server.xml文件中的节点
然后在标签下面添加修改项目默认路径
path:如果为空则表示去掉访问路径中的项目名称
docBase:表示项目的路径(建议使用绝对路径)
按上述第三条修改后
原来的项目访问路径 http://localhost:8082/项目名称/方法名称,变成http://localhost:8082/方法名称,将项目名称去掉。
文章来源: Linux部署spring boot war项目