🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
目录 [TOC] ## 修改pom文件 packaging修改为war spring-boot-starter-web去除tomcat依赖 添加servlet依赖 ![](https://img.kancloud.cn/68/6d/686d0d966192453c6137d9df1de3675f_1106x898.png) 添加新的tomcat运行方式 ![](https://img.kancloud.cn/fc/a6/fca61d9100fa7a85c21b06cf81acee12_450x154.png) ![](https://img.kancloud.cn/c1/91/c1919eb50c2d2bc3bfd91f587e8e9869_178x254.png) ![](https://img.kancloud.cn/6f/0e/6f0eb0dce4f6947d22816f93e036769d_1112x1346.png) ![](https://img.kancloud.cn/4c/fb/4cfb469deb40119e8394ac14c2a467f4_1958x1314.png) 指定当前开发项目 ![](https://img.kancloud.cn/d7/32/d7323e9c719f5cf0164c445126ff4da2_1958x1314.png) ![](https://img.kancloud.cn/4b/3f/4b3fed26ee741b2ae76722a4d43227b9_952x988.png) 改为/ ![](https://img.kancloud.cn/06/7d/067dca3318f346a7b30e335a9d554a28_1958x1314.png) ## 继承SpringBootServletInitializer重写configure方法 ` ~~~ package xxxx; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class DemoApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(this.getClass()); } } ~~~ ` ***** 写个Contoller用于测试 ~~~ package xxxxxx; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class Example { @RequestMapping("/CC") String home() { return "Hello World!1"; } } ~~~ ***** ## 点击运行tomcat启动服务 ![](https://img.kancloud.cn/32/5a/325a9a8873afc4fa7cbf7282f5786f9d_570x62.png) 服务成功启动 ![](https://img.kancloud.cn/e4/0c/e40cf662fcc4493c80f6999a62cebf83_2812x830.png) 服务可以成功访问 ![](https://img.kancloud.cn/4d/7a/4d7a22de9733c07f6c16549ccddc80f9_1080x306.png)