springboot打war包

 

1.<!-- 打包war [1] --><packaging>war</packaging>

 

2.

 <!--web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--移除SpringBoot内置的toncat  打war包[2]-->
           <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>

 

 

3.

<!-- 打包war [3] 添加依赖 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

 

 

  1. 跟springboot的启动类的同级目录下创建WarStarterApplication启动类

    ​
    import org.springframework.boot.builder.SpringApplicationBuilder;
            import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    ​
    // 打包war [4] 增加war的启动类
    public class WarStarterApplication extends SpringBootServletInitializer {
    ​
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            // 指向Application这个springboot启动类
            return builder.sources(Application.class);
        }
    }

     


     

5.先把clean一下jar包

6.在安装一下install

 

posted @ 2021-05-23 18:58  Amy清风  阅读(142)  评论(0编辑  收藏  举报