build.gradle
apply plugin: 'java'
dependencies {
providedCompile("org.springframework.boot:spring-boot-starter-tomcat")
}
new File
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SchwetzingenAssessmentApplication.class);
}
}
打包
grade build
多配置文件
在使用SpringBoot内嵌的Tomcat时,我们一般使用java -jar的方式启动,这时我们通过--spring.profiles.active=dev
传参来使用不同配置文件,但用过外部Tomcat发布时无法使用这种方式,但是我们可以在主配置文件application.properties
中添加spring.profiles.active
来读取不同的配置文件这样我们打包成的war包加载的就是我们想要的配置了。