SpringBoot工程可执行jar修改为可执行war
三步骤简述
1. 主程序继承SpringBootServletInitializer,并重写configure方法
2. POM文件,打包为jar改为打包为war。<packaging>war</packaging>
3. 内嵌的Servlet容器scope改为provided。<scope>provided</scope>
结果:war包即可以放在Servlet容器,比如tomcat的webapps下面运行,也可以通过jar -jar demo.war的方式运行
@SpringBootApplication public class DemoApplication extends SpringBootServletInitializer{ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } -------------------------------------------------------------------------- <groupId>com.hepengju</groupId> <artifactId>demo</artifactId> <version>0.0.1</version> <packaging>war</packaging> -------------------------------------------------------------------------- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
SpringBoot的一些有意思的知识
1. dev-tools的触发文件名称为.reloadtrigger时, STS,IDEA的终端会出现reload图标
2. 可执行war包的处理:主程序类继承SpringBootServlet初始化器,pom改为war,tomcat改为provided
3. StopWatch打印每个任务的耗时及百分比
4. 获取程序PID:ApplicationPid、StartupInfoLogger.getStartingMessage()、ApplicationPidFileWriter
5. lsof -i:6379 查询占用这个端口的文件