本文转载自:https://www.cnblogs.com/yanpeng19940119/p/15810649.html
启动类配置
继承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>
移除内置Tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
WebSocket错误
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Bean按需加载
@Configuration
public class WebSocketConfig {
@Bean
@ConditionalOnProperty(name = "system.package", havingValue = "jar", matchIfMissing = true)
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
Tomcat设置
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初始化两次
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
本文链接:https://www.jhelp.net/p/py7enwgBvR59XqOZ (转载请保留)。
关注下面的标签,发现更多相似文章
本站推荐
-
549
-
526
-
521
-
512
-
503
文章目录