SpringBoot打成war包并部署

1.pom中打包方式修改为war
    <packaging>warpackaging>
2.引入javax-servlet-api
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>javax.servlet-apiartifactId>
            <scope>providedscope>
        dependency>
3.排除springboot内嵌的tomcat
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-starter-webartifactId>
                exclusion>
            exclusions>
        dependency>
4.启动类继承SpringBootServletInitializer并重写configure()方法
public class SpringCacheApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(SpringCacheApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // 指向核心启动类
        return builder.sources(SpringCacheApplication.class);
    }
}
5.maven打包

SpringBoot打成war包并部署_第1张图片

6.本地部署并访问

SpringBoot打成war包并部署_第2张图片

end

你可能感兴趣的:(java,spring,boot,java,后端,tomcat)