springboot项目打包成war包部署到外部的tomcat
先在pom.xml文件里引入webflux依赖包:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
在项目里添加一个额外的类即可:
import com.my.Application;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.adapter.AbstractReactiveWebInitializer;
@Slf4j
@Configuration
@ConditionalOnMissingBean(ReactiveWebServerFactory.class)
public class ConfigReactiveWebInitializer extends AbstractReactiveWebInitializer {
@Override
protected ApplicationContext createApplicationContext() {
log.info("ConfigReactiveWebInitializer step 1. createApplicationContext" );
SpringApplication springApplication = new SpringApplication(getConfigClasses());
return springApplication.run();
}
@Override
protected Class<?>[] getConfigClasses() {
log.info("ConfigReactiveWebInitializer step 2. setConfigClasses = Application.class" );
return new Class[]{ Application.class }; // 就是你的启动类
}
@Bean
public NettyReactiveWebServerFactory nettyReactiveWebServerFactory() {
log.info("ConfigReactiveWebInitializer step 3. register bean NettyReactiveWebServerFactory" );
return new NettyReactiveWebServerFactory();
}
}
配置application.properties:
server.port=8095
server.servlet.context-path=/my-service
spring.application.name=my-service
spring.main.web-application-type=reactive
spring.main.allow-bean-definition-overriding=true
management.endpoint.health.show-details=always
spring.profiles.active=
# 包含这些额外的properties文件:application-cron.properties; application-redis.properties; application-rabbitmq.properties;
spring.profiles.include=cron,redis,rabbitmq
end.

分类:
webflux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界