1. 程式人生 > >SpringBoot maven 打 war 部署Tomcat

SpringBoot maven 打 war 部署Tomcat

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 packagewar, 拷貝到 Tomcat webapps 下面 啟動 Tomcat 。