Springboot项目打成war包教程

一、修改项目pom.xml文件

1、修改打包方案
在这里插入图片描述
2、排除内嵌的tomcat,引入javax.servlet-api

<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-tomcatartifactId>
    <scope>providedscope>
dependency>
<dependency>
    <groupId>javax.servletgroupId>
    <artifactId>javax.servlet-apiartifactId>
    <scope>providedscope>
dependency>

3、引入maven-war-plugin插件

     <plugin>
         <groupId>org.apache.maven.pluginsgroupId>
         <artifactId>maven-war-pluginartifactId>
         <version>3.3.1version>
         <configuration>
             <failOnMissingWebXml>falsefailOnMissingWebXml>
         configuration>
     plugin>

4、如果存在图中配置,注释掉,否则会报复制 jar 包错误
Springboot项目打成war包教程_第1张图片

二、修改Application类

修改项目默认启动方式,启动类继承SpringBootServletInitializer类重写configure()方法

@EnableBladeFeign
@SpringCloudApplication
public class EvaluateApplication extends SpringBootServletInitializer {

	public static void main(String[] args) {
		BladeApplication.run("blade-aa", EvaluateApplication.class, args);
	}
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return BladeApplication.createSpringApplicationBuilder("blade-aa", EvaluateApplication.class).sources(EvaluateApplication.class);
	}
}

你可能感兴趣的:(代码,java,spring)