SpringBoot在Tomcat部署war包
启动类配置
【SpringBoot在Tomcat部署war包】继承SpringBootServletInitializer
@SpringBootApplication
public class TestApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TestApplication.class);
}
}
打包方式配置
war
移除内置Tomcat
org.springframework.boot
spring-boot-starter-tomcat
provided
WebSocket错误
javax.servlet
javax.servlet-api
3.1.0
provided
Bean按需加载
@Configuration
public class WebSocketConfig {
@Bean
@ConditionalOnProperty(name = "system.package", havingValue = "https://www.it610.com/article/jar", matchIfMissing = true)
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
Tomcat设置 Host节点增加Context可以直接通过ip+端口方式访问,需要将appBase清除,防止启动两次应用
注意事项 对于框架封装引用jar包,需要注意工程项目中只能有一个类继承自SpringBootServletInitializer,否则会导致ApplicationContext初始化两次
推荐阅读
- 你到家了吗
- 闲杂“细雨”
- 杜月笙的口才
- 赢在人生六项精进二阶Day3复盘
- 祖母走了
- 樱花雨
- 眼观耳听美食的日子
- Activiti(一)SpringBoot2集成Activiti6
- “成长”读书社群招募
- 眉头开了