spring-boot war包

接着上面的spring-boot项目,直接使用jar包方便调试,在开发阶段非常方便,生产上最好打成war形式

要想spring-boot打war包,还是从pom.xml入手

1.1 调整pom.xml

<packaging>war</packaging>
<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.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>7.0.42</version> <scope>provided</scope> </dependency>

打包改为war,排除嵌入的tomcat,provided编译需要的jar依赖

1.2 添加类

在MyApplication.jar同包下添加类MySpringBootServletInitializer

@Configuration
public class MySpringBootServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class);
    }
}

 

好了,简单两步就可以使用maven package打包了,发到tomcat容器看看吧

 

posted @ 2017-04-06 17:20  未来的那啥  阅读(921)  评论(0编辑  收藏  举报