一、修改gradle.build文件
1.1 添加如下配置
apply plugin: 'war'
1.2 修改依赖,将tomcat的依赖范围修改为providedCompile
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
providedCompile("org.springframework.boot:spring-boot-starter-tomcat")
testCompile('org.springframework.boot:spring-boot-starter-test')
如图:
image.png
二、主类继承SpringBootServletInitializer,重写configure方法
@SpringBootApplication
public class ServerApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServerApplication.class);
}
}
三、构建
进入项目路径,执行命令:gradle build。成功后会在build/libs下生成war包。
网友评论