I'm slowly stepping in Java world through Spring Framework (4.1.0) and need your help with Listeners.
I have created application without deployment descriptor, all Spring related configuration is managed in @Configuration
annotated classes. Everything is working but I can't find a way to register listeners.
Question: How I can register listeners in Spring (4.1.0) based on Java @Configuration
annotated classed ?
You do that with the help of the WebApplicationInitializer class. @Configuration
is for Spring configurations, not for the deployment descriptor.
public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
container.addListener(...);
...
}
}
You can find more explanations here: How to use Spring's WebApplicationInitializer.
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