1.pom.xml设置项目工程的打包方式为war
<packaging>war</packaging>
2.增加下面依赖配置 spring-boot-starter-tomcat的范围设置为provided
org.springframework.boot spring-boot-starter-tomcat provided
3.修改启动类,继承SpringBootServletInitializer 然后重写configure方法
@SpringBootApplicationpublic class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication application = new SpringApplication(Application.class); //设置启动时是否显示banner图 application.setBannerMode(Banner.Mode.OFF); application.run(args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { //设置启动类,用于独立tomcat的入口 return builder.sources(Application.class); }}
4.打war包,选择项目右键 maven build.. 输入clean package 点击run
5.将上面产生的war包部署到独立的tomcat即可