美文网首页
springboot 以war包形式运行

springboot 以war包形式运行

作者: 唯爱米 | 来源:发表于2019-04-13 20:21 被阅读0次

    1.将springboot默认的tomcat禁用

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

    2.添加一个不为人知的插件

    <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.4.2</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
     </plugin>
    

    3.把jar改成war

    <packaging>war</packaging>
    

    4.main方法继承SpringBootServletInitializer 实现 SpringApplicationBuilder

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

    相关文章

      网友评论

          本文标题:springboot 以war包形式运行

          本文链接:https://www.haomeiwen.com/subject/iobmbqtx.html