Example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext.

Prototype

public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc)
        throws IllegalStateException 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:net.kamhon.ieagle.application.Application.java

protected static synchronized ApplicationContext initialize(final ServletContext servletContext) {
    try {//from  w w  w.  j  a  v  a 2  s  . c  o m
        if (appContext == null) {
            appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        }
    } catch (Exception ex) {
        log.info("WebApplicationContext not found!!! Using ClassPathXmlApplicationContext");

        if (StringUtils.isBlank(contextPath)) {
            initContextPath();
        }

        try {
            if (appContext == null && contextPath.endsWith(".class")) {
                appContext = new AnnotationConfigApplicationContext(
                        Class.forName(contextPath.substring(0, contextPath.length() - ".class".length())));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            if (appContext == null)
                appContext = new FileSystemXmlApplicationContext(contextPath);
        } catch (Exception e) {
        }

        try {
            if (appContext == null)
                appContext = new ClassPathXmlApplicationContext(contextPath);
        } catch (Exception e) {
        }

        createGenericApplicationContext();
    }

    return appContext;
}

From source file:net.sourceforge.vulcan.web.PreferencesFilter.java

@Override
protected void initFilterBean() throws ServletException {
    super.initFilterBean();

    store = (PreferencesStore) WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext())
            .getBean("preferencesStore", PreferencesStore.class);
}

From source file:com.preserve.core.listener.StartupListener.java

@SuppressWarnings("unchecked")
@Override//ww w .  j  av  a2  s . c om
public void contextInitialized(ServletContextEvent sce) {
    ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context = sce.getServletContext());
    //        UserService service=(UserService)ctx.getBean("userService");
    //        User u =new User();
    //        u.setName("test1");
    //        u.setPwd("12312");
    //        service.save(u);

    //        appDao = ctx.getBean(AppDao.class);
    //        tagDao = ctx.getBean(TagDao.class);
    //        appCache = ctx.getBean("appCache", Map.class);
    //        loadAppConfig();
    //        loadTags();
    //        loadSkinMessage();
    //        loadSkins();
    setWebProperty();
}

From source file:no.kantega.kwashc.server.ServerJettyStarter.java

public static <T> T getSpringBean(Class<T> beanClass) {
    ServletContext servletContext = webAppContext.getServletHandler().getServletContext();
    WebApplicationContext springWebAppContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    return springWebAppContext.getBean(beanClass);
}

From source file:org.wicketstuff.shiro.example.spring.ExampleSpringApp.java

public ApplicationContext context() {
    return WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}

From source file:org.araneaframework.ioc.spring.AraneaSpringDispatcherServlet.java

public void init() throws ServletException {
    beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    super.init();
}

From source file:works.cirno.mocha.SpringDispatcherFilter.java

@Override
protected ObjectFactory getMVCFactory() {
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    return SpringMVCFactory.fromCustomApplicationContext(ctx);
}

From source file:com.ultrapower.eoms.common.plugin.ecside.filter.ExportFilterUtils.java

public static Object getBean(HttpServletRequest request,String beanName){
   Object bean=null;/*from  ww w  .  j a  v  a 2  s. c o m*/
   ApplicationContext appContext=WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession(true).getServletContext());
   bean=appContext.getBean(beanName);
   if (bean==null){
      LogHandler.warnLog(logger,ECSideFilter.class," Can't find DataAccess Bean named "+beanName);
   }
   return bean;
}

From source file:org.fcrepo.indexer.webapp.FedoraIndexer.java

/**
 * Servlet initialization.//from   w ww.j  av a 2s . co m
**/
public void init(final ServletConfig sc) throws ServletException {
    super.init(sc);
    final WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    indexer = (IndexerGroup) ctx.getBean(sc.getInitParameter("beanName"));
}

From source file:com.sbu.controller.Update_Form_Startup_Controller.java

@Override
public void init() throws ServletException {
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    jobpositionService = context.getBean(JobPositionManager.class);
    memberService = context.getBean(MemberManager.class);
    startupService = context.getBean(StartupManager.class);
    feedService = context.getBean(FeedManager.class);
}