grade 添加war插件
apply plugin: ‘war’
War插件 添加了两个依赖配置项providedCompile 和 providedRuntime,这两个配置项分别和compile和runtime有相同的作用域,只是不将依赖打包到war文件
添加依赖
注意:org.springframework.boot:spring-boot-starter-web 内置了tomcat容器,因为要部署到tomcat所以要在打包war的时候将其排除出去,所以使用了providedRuntime
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE")
providedRuntime 'org.springframework.boot:spring-boot-starter- tomcat:1.5.2.RELEASE'
}
[grade java plugin](https://docs.gradle.org/current/userguide/java_plugin.html)
[grade war plugin]([grade java plugin](https://docs.gradle.org/current/userguide/java_plugin.html))
- 继承 SpringBootServletInitializer类并且重写** configure**方法
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
- 打包成war文件
gradle war
执行命令将在工程目录下的build/libs/目录生成war文件 将该文件放到tomcat的webapps目录下启动tomcat 搞定。。。。
spring boot可用参数配置列表
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html