Spring Boot 2.0 内嵌 Tomcat 定制 : WebServerFactoryCustomizer

本文介绍了如何在SpringBoot 2.0中使用WebServerFactoryCustomizer接口来定制内嵌Tomcat的配置,包括设置端口等。此方法替代了SpringBoot 1.x中使用的EmbeddedServletContainerCustomizer接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Boot 2.0 内嵌 Tomcat 定制 : WebServerFactoryCustomizer

在 Spring Boot 1.x 中 ,我们通过 EmbeddedServletContainerCustomizer 接口调优 Tomcat 自定义配置。 在Spring Boot 2.0 中,通过 WebServerFactoryCustomizer 接口定制。

As far as the port is concerned, I'd use the configuration option as already answered.

However, you can still use a customizer, however, the types and location will change in Spring Boot 2.0, see:

import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;

@Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

@Override
public void customize(ConfigurableServletWebServerFactory server) {
    server.setPort(9000);
}

}

https://stackoverflow.com/questions/43571505/how-to-find-the-interface-embeddedservletcontainercustomizer-in-spring-boot-2-0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值