I have written a customcontextloaderlistener and it gets called when the web application starts up.
public class CustomContextLoaderListener extends ContextLoaderListener {
private Logger log = Logger.getLogger(CustomContextLoaderListener.class);
public void contextInitialized(ServletContextEvent sce){
WebApplicationContext wctx = new ContextLoader().initWebApplicationContext(sce.getServletContext());
AppContext.setWebApplicationContext(wctx);
wctx.getBeanDefinitionCount();
String [] beanNames = wctx.getBeanDefinitionNames();
for(String beanName : beanNames){
log.info(beanName);
}
Now if there is an error in bean initialization I would like to stop the web application. So I am thinking I can do something like this.
public class CustomContextLoaderListener extends ContextLoaderListener {
private Logger log = Logger.getLogger(CustomContextLoaderListener.class);
public void contextInitialized(ServletContextEvent sce){
try {
WebApplicationContext wctx = new ContextLoader().initWebApplicationContext(sce.getServletContext());
AppContext.setWebApplicationContext(wctx);
wctx.getBeanDefinitionCount();
String [] beanNames = wctx.getBeanDefinitionNames();
for(String beanName : beanNames){
log.info(beanName);
}
}catch(Exception e) {
contextDestroyed(sce)
}
public void contextDestroyed(ServletContextEvent sce) {
// not sure how should I stop the web app here..
any ideas
}