首页 > 代码库 > 如何打一个可执行war包并使之可以部署在tomcat服务器上

如何打一个可执行war包并使之可以部署在tomcat服务器上

https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/

1、首先你的pom文件中需要包含内嵌tomcat:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
 </dependency>
2、其次需要使用spring-boot-maven-plugin来打包pom中加上
    <build>
        <plugins>
            <!-- Package as an executable jar/war -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

 3、最后你的app要继承SpringBootServletInitializer如:

@SpringBootApplication
public class SpringBootWebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootWebApplication.class);
    }

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

}

 

 

如何打一个可执行war包并使之可以部署在tomcat服务器上