Add ServletContextListener to embedded web app
* User can add @Bean of type EventListener (e.g. ServletContextListener) [Fixes #54112999] [bs-254]
This commit is contained in:
@@ -16,8 +16,14 @@
|
||||
|
||||
package org.springframework.boot.sample.tomcat;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -26,8 +32,25 @@ import org.springframework.context.annotation.Configuration;
|
||||
@ComponentScan
|
||||
public class SampleTomcatApplication {
|
||||
|
||||
private static Log logger = LogFactory.getLog(SampleTomcatApplication.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleTomcatApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected ServletContextListener listener() {
|
||||
return new ServletContextListener() {
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
logger.info("ServletContext initialized");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
logger.info("ServletContext destroyed");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user