Spring Boot除了可以打可执行jar包外,也支持传统的war包。本文介绍如何使用Spring Boot构建传统war包。

成都创新互联主要业务有网站营销策划、做网站、成都网站建设、微信公众号开发、微信小程序定制开发、HTML5建站、程序开发等业务。一次合作终身朋友,是我们奉行的宗旨;我们不仅仅把客户当客户,还把客户视为我们的合作伙伴,在开展业务的过程中,公司还积累了丰富的行业经验、全网整合营销推广资源和合作伙伴关系资源,并逐渐建立起规范的客户服务和保障体系。
Spring Boot打war包步骤如下:
1、在pom.xml里定义打包类型
war 
2、添加Spring Boot启动器(也可通过parent)
org.springframework.boot spring-boot-dependencies 1.5.6.RELEASE pom import 
3、添加spring-boot-starter-web依赖
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat 
4、添加打包插件
org.springframework.boot spring-boot-maven-plugin 
5、主类继承SpringBootServletInitializer
/**
 * WAR application
 */
@SpringBootApplication
public class WarApplication extends SpringBootServletInitializer {
 
 public static void main(String[] args) {
 SpringApplication.run(WarApplication.class, args);
 }
}6、执行mvn clean package打包
$mvn clean package
7、将打好的war包拷贝到容器(如tomcat)运行即可。
这里需要简单说明下:
主应用可以重写SpringBootServletInitializer里面有configure方法,自定义配置Spring Boot。
  /**
 * Configure the application. Normally all you would need to do is to add sources
 * (e.g. config classes) because other settings have sensible defaults. You might
 * choose (for instance) to add default command line arguments, or set an active
 * Spring profile.
 * @param builder a builder for the application context
 * @return the application builder
 * @see SpringApplicationBuilder
 */
 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
 return builder;
 }实例源码下载
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。