servlet context parameters will be replaced by ServletWebServerFactoryCustomizer when providing a custom TomcatServletWebServerFactory
I used @Bean to customize TomcatServletWebServerFactory,and set the servlet context parameters, but the parameters replaced by ServletWebServerFactoryCustomizer get from org.springframework.boot.autoconfigure.web.ServerProperties, Is this a bug ?
Here is my @Bean code
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
TomcatServletWebServerFactory tomcatServletWebServerFactory =
new TomcatServletWebServerFactory();
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("param1", "value1");
hashMap.put("param2", "value2");
tomcatServletWebServerFactory.setInitParameters(hashMap);
return tomcatServletWebServerFactory;
}
But the following code will replace my parameter settings
Comment From: mbhave
This is happening because the WebServerFactoryCustomizers are applied not just to the auto-configured TomcatServletWebServerFactory bean but also to a user-provided TomcatServletWebServerFactory bean. Ideally, we'd like the customizers to apply only to the auto-configured bean as that aligns with the other customizers. This would, however, be a breaking change and we've decided to hold off on this till 3.0.
@brucelwl For your case, you would need to configure a bean of type WebServerFactoryCustomizer which would be ordered so that it is applied after ServletWebServerFactoryCustomizer. You could either move all of your customization logic there instead of adding a bean for TomcatServletWebServerFactory, or just move the bits that overridden by ServletWebServerFactoryCustomizer.
Comment From: mbhave
I think #24706 supersedes this one.