https://www.jb51.net/article/202524.htm
1 pom.xml修改
1.1 新增依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
1.2 排除springboot内置tomcat
<dependency>
<groupId>com.sinosoft</groupId>
<artifactId>base-core</artifactId>
<version>2.7.1</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
1.3 maven编译插件
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
2 启动类修改
原启动类:
@SpringBootApplication
public class SystemManageApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SystemManageApplication.class, args);
PrintApplicationInfo.print(context);
}
}
让启动类继承SpringBootServletInitializer,如下:
@SpringBootApplication
public class SystemManageApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SystemManageApplication.class, args);
PrintApplicationInfo.print(context);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SystemManageApplication.class);
}
}
3 打包
打包方式和打jar包相同。在idea中,依次执行clean、package即可完成打包: 执行完成后,在target文件中,可以看到已经打好的war包:
或在Terminal中使用命令 mvn clean package 进行打包:
|