1.排除嵌入式tomcat,修改pom文件
由于SpringBoot自带嵌入容器,如果要部署到外部tomcat,打包之前就需要把嵌入tomcat排除在外(注掉下面自带依赖):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
同时将:
<packaging>jar</packaging>
修改为:
<packaging>war</packaging>
2.注册启动类
修改启动类继承SpringBootServletInitializer类,并重写configure方法:
@SpringBootApplication
public class App extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(App.class);
}
}
3.用maven命令打包
image.png
4.有时候打出的包名字太长运行项目输入路径不方便,可以对打出的包名进行修改
<build>
<finalName>myDreamTest</finalName>
</build>
网友评论