spring boot项目打war包

spring boot打war包仅需要三步走:

  1、首先需要继承 org.springframework.boot.web.support.SpringBootServletInitializer 并实现 configure方法

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

  2、修改pom.xml文件中的打包方式,改成war

<modelVersion>4.0.0</modelVersion>
  <groupId>com.study</groupId>
  <artifactId>blogs</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>

  3、在pom.xml文件中添加打成war包所需要的tomcat依赖

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

  

  可以在target目录下看到war包,然后放进tomcat容器中运行

  至此打包完成!

posted @ 2018-08-26 21:41  岂曰  阅读(183)  评论(1)    收藏  举报