spring-boot war包
接着上面的spring-boot项目,直接使用jar包方便调试,在开发阶段非常方便,生产上最好打成war形式
要想spring-boot打war包,还是从pom.xml入手
1.1 调整pom.xml
<packaging>warpackaging>
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-webartifactId> <exclusions> <exclusion> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-tomcatartifactId> exclusion> exclusions> dependency>
<dependency> <groupId>org.apache.tomcatgroupId> <artifactId>tomcat-servlet-apiartifactId> <version>7.0.42version> <scope>providedscope> 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容器看看吧