最新消息: 新版網站上線了!!!

解決Spring Boot+maven打war包常見錯誤

1.指定war打包方式

<packaging>jar</packaging>

2.pom.xml添加spring-boot-maven-plugin插件

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>2.0.1.RELEASE</version>
      <executions>
        <execution>
          <goals>
            <goal>repackage</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

3.pom.xml添加spring-boot-starter-tomcat依賴

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
  <scope>provided</scope>
</dependency>

4.啟動類繼承SpringBootServletInitializer并重寫configure方法

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
  }
  public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
  }
}


轉載請注明:谷谷點程序 » 解決Spring Boot+maven打war包常見錯誤

体彩25选5开奖号码