My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Friday, December 4, 2015

Spring Custom Context Loader


Use Spring Custom Context Loader.


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import com.fra.exception.ApplicationException;
import com.fra.exception.SystemException;
import com.fra.fv.service.IModuleConfigService;

@WebListener
public class CustomContextListener implements ServletContextListener {
 @Autowired
 @Qualifier(value = "mdlConfigService")
 IModuleConfigService mdlConfigService;
 final static Logger logger = Logger.getLogger(CustomContextListener.class);

 public CustomContextListener() {
  super();
 }

 @Override
 public void contextInitialized(ServletContextEvent event) {
  SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
  try {
   mdlConfigService.loadModuleConfigs();
  } catch (ApplicationException e) {
   logger.error(ExceptionUtil.getFullExceptionAsString(e, 50));
  } catch (SystemException e) {
   logger.error(ExceptionUtil.getFullExceptionAsString(e, 50));
  }
 }

 @Override
 public void contextDestroyed(ServletContextEvent event) {
 }
}

No comments :