继承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);
}
}
<packaging>war</packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
@Configuration
public class WebSocketConfig {
@Bean
@ConditionalOnProperty(name = "system.package", havingValue = "jar", matchIfMissing = true)
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
Host节点增加Context可以直接通过ip+端口方式访问,需要将appBase清除,防止启动两次应用
<Host name="localhost" appBase="" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="webapps/test" reloadable="false"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
对于框架封装引用jar包,需要注意工程项目中只能有一个类继承自SpringBootServletInitializer,否则会导致ApplicationContext初始化两次
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有