We are using the next interfaces in Spring Boot 1.5.9, working without any problem: ConfigurableEmbeddedServletContainer
and EmbeddedServletContainerCustomizer
.
We have upgraded to Spring Boot 2 (2.0.0.M7), and these interfaces don't exist. We think they have been modified for other interfaces with the same purpose but we don't know what they are.
Could somebody help us in order to know how to modify this piece of code for having the same behaviour we had in Spring 1.5.9?
The code we have is the next:
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() throws FileNotFoundException {
final TomcatConnectorCustomizer customizer = new MyTomcatConnectionCustomizer(absoluteKeystoreFile,
keystoreType, keystorePassword);
return new EmbeddedServletContainerCustomizer() {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) container;
containerFactory.addConnectorCustomizers(customizer);
Connector connector = new Connector(TomcatEmbeddedServletContainerFactory.DEFAULT_PROTOCOL);
connector.setPort(port);
containerFactory.addAdditionalTomcatConnectors(connector);
}
}
};
}
public interface EmbeddedServletContainerCustomizer. Strategy interface for customizing auto-configured embedded servlet containers. Any beans of this type will get a callback with the container factory before the container itself is started, so you can set the port, address, error pages etc.
public class TomcatEmbeddedServletContainerFactory extends AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware. EmbeddedServletContainerFactory that can be used to create TomcatEmbeddedServletContainer s. Can be initialized using Spring's ServletContextInitializer s or Tomcat LifecycleListener s.
public class TomcatServletWebServerFactory extends AbstractServletWebServerFactory implements ConfigurableTomcatWebServerFactory, ResourceLoaderAware. AbstractServletWebServerFactory that can be used to create TomcatWebServer s.
SpringBootServletInitializer is an interface to run SpringApplication from a traditional WAR deployment. It binds Servlet, Filter and ServletContextInitializer beans from the application context to the server.
You need to return an implementation of ConfigurableServletWebServerFactory
as a bean, in your case TomcatServletWebServerFactory
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
final TomcatConnectorCustomizer customizer = new MyTomcatConnectionCustomizer(absoluteKeystoreFile,
keystoreType, keystorePassword);
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(connector -> {
connector.setPort(port);
}, customizer);
return factory;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With