SpringBoot项目打包成war
文章目录
SpringBoot项目默认是打包成jar,如果我们想把SpringBoot项目打包成war,可以按照以下步骤就行操作:
-
在pom文件中修改打包方式为war
<packaging>war</packaging> -
移除springboot web模块中自带的tomcat
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <artifactId>spring-boot-starter-tomcat</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> -
在pom文件中添加servlet的依赖
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> -
在Application启动类同一包下面新建WarStarterApplication类,继承
SpringBootServletInitializer类,并重写configure方法public class WarStarterApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { //指向Application启动类 return builder.sources(Application.class); } } - maven install即可打包成war

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论