SpringBoot maven 打 war 部署Tomcat
阿新 • • 發佈:2018-11-26
pom.xml 新增一個依賴和外掛
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml >
</configuration>
</plugin>
</plugins>
</build>
啟動檔案需要 繼承 SpringBootServletInitializer
, 並重寫 configure
@SpringBootApplication
public class MainApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(MainApplication.class);
}
}
切換到專案根目錄,mvn clean package
打 war
, 拷貝到 Tomcat webapps 下面 啟動 Tomcat 。