The problem of springboot playing war package

1. First modify the packaging method under pom.xml

<packaging>war</packaging>
2. Add servlet-api dependency

<!--Add servlet-api dependency-->
<dependency>
    <groupId>javax.servlet</ groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
3. Remove the tomcat module embedded in springboot

<dependency>
    <groupId >org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- remove embedded tomcat plugin-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework. boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

4. Modify the compilation settings

Method 1:
<build>
  <plugins>
    <plugin>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.6</version>
      < configuration>
        <!-- Set to false if you want to build the WAR without a web.xml file. -->     
        <failOnMissingWebXml>false</failOnMissingWebXml>                       
      </configuration>
    </plugin>
  </plugins>
</build>

Method 2:
Add the following configuration to the pom.xml file

Version 3.0.0 plugin web.xml does not exist problem, so the problem can be solved by upgrading the plugin
<plugin>
  <

</plugin>

5.修改启动类

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(this.getClass());
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263177&siteId=291194637