美文网首页
Spring Boot 打war包

Spring Boot 打war包

作者: GoGooGooo | 来源:发表于2017-06-07 11:50 被阅读3587次
  1. 将SpringBoot的项目的打包方式设置为war
 <groupId>com.example</groupId>  
<artifactId>demo</artifactId>  
<version>1.0.0</version>  
<packaging>war</packaging>
  1. 移除内嵌的tomcat模块,但是为了我们在本机测试方便,我们还需要引入它,所以配置如下
<dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-web</artifactId>  
        <exclusions>  
            <exclusion>  
                <groupId>org.springframework.boot</groupId>  
                <artifactId>spring-boot-starter-tomcat</artifactId>  
            </exclusion>  
        </exclusions>  
</dependency>  
<dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-tomcat</artifactId>  
        <scope>provided</scope>  
</dependency>  
  1. 添加tomcat-servelt-api依赖
<dependency>  
      <groupId>org.apache.tomcat</groupId>  
      <artifactId>tomcat-servlet-api</artifactId>  
      <version>7.0.42</version>  
      <scope>provided</scope>  
</dependency>  
  1. 修改入口方法 继承一个SpringBootServletInitializer类,并且覆盖configure方法
package com.example;  
  
   import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication;  
import org.springframework.boot.builder.SpringApplicationBuilder;  
import org.springframework.boot.web.support.SpringBootServletInitializer;  
import org.springframework.cache.annotation.EnableCaching;  
  
   @SpringBootApplication  
@EnableCaching  
public class SpringDataJpaExampleApplication extends SpringBootServletInitializer {  
  
    @Override  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
        return application.sources(SpringDataJpaExampleApplication.class);  
    }  
  
    public static void main(String[] args) {  
        SpringApplication.run(SpringDataJpaExampleApplication.class, args);  
    }  
}  
  1. 添加war插件,用来自定义打包以后的war包的名称
<plugin>  
      <groupId>org.apache.maven.plugins</groupId>  
      <artifactId>maven-war-plugin</artifactId>  
      <configuration>  
          <warSourceExcludes>src/main/resources/**</warSourceExcludes>  
          <warName>springboot</warName>  
      </configuration>  
</plugin>  

引入上面这个插件,是避免maven打包的时候为我们默认的一个带有版本号的war包名称,因为我们部署到tomcat以后,在访问项目的时候,需要用到这个war包的名称

相关文章

网友评论

      本文标题:Spring Boot 打war包

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