Reputation: 303
We are trying to add a our own listener in Spring boot application like :
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
>
How do we add this in a Spring boot application?
Upvotes: 0
Views: 3706
Reputation: 1297
In the latest version of spring boot the implementation has changed.
@Component
public class MyTomcatWebServerCustomizer
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
// customize the factory here
}
}
Upvotes: 2
Reputation: 1384
Just by add this config class to your project:
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Created by [email protected] on 16/10/28.
*/
@Configuration
public class TomcatConfig implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
}
@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.addContextLifecycleListeners(null);
return factory;
}
}
And more detail here:spring boot document
Upvotes: 3