Example usage for org.springframework.web.context.support GenericWebApplicationContext setId

List of usage examples for org.springframework.web.context.support GenericWebApplicationContext setId

Introduction

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

Prototype

@Override
public void setId(String id) 

Source Link

Document

Set the unique id of this application context.

Usage

From source file:fr.paris.lutece.portal.service.spring.SpringContextService.java

/**
 * Initialize a global Application Context containing all beans (core + plugins)
 * Now uses GenericApplicationContext for better performances. A wrong formatted file
 * will not block block context to be built (without the file), but a wrong bean (i.e. cannot
 * be instantiated) will cause a full context failure. Context is less "failure-friendly"
 * @param servletContext The servlet context
 * @throws LuteceInitException The lutece init exception
 * @since 2.4/*from www  . ja  va  2s  . c  o  m*/
 */
public static void init(ServletContext servletContext) throws LuteceInitException {
    try {
        // Register this service as a PluginEventListener
        PluginService.registerPluginEventListener(_instance);

        // timing
        Date dateBegin = new Date();

        // Load the core context file : core_context.xml
        String strConfPath = AppPathService.getAbsolutePathFromRelativePath(PATH_CONF);
        String strContextFile = "file:" + strConfPath + FILE_CORE_CONTEXT;

        GenericWebApplicationContext gwac = new GenericWebApplicationContext(servletContext);
        gwac.setId(getContextName(servletContext));

        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(gwac);
        xmlReader.loadBeanDefinitions(strContextFile);

        // _context = new ClassPathXmlApplicationContext( strContextFile );
        AppLogService.info("Context file loaded : " + FILE_CORE_CONTEXT);

        // Load all context files found in the conf/plugins directory
        // Files are loaded separatly with an individual try/catch block
        // to avoid stopping the process in case of a failure
        // The global context generation will fail if a bean in any file cannot be built.
        String strConfPluginsPath = strConfPath + DIR_PLUGINS;
        File dirConfPlugins = new File(strConfPluginsPath);
        FilenameFilter filterContext = new ContextFileFilter();
        String[] filesContext = dirConfPlugins.list(filterContext);

        loadContexts(filesContext, strConfPluginsPath, xmlReader);

        // we now load overriding beans
        AppLogService.info("Loading plugins context overrides");

        String strCoreContextOverrideFile = strConfPath + DIR_OVERRIDE + FILE_CORE_CONTEXT;
        File fileCoreContextOverride = new File(strCoreContextOverrideFile);

        if (fileCoreContextOverride.exists()) {
            AppLogService.debug("Context file loaded : core_context");
            xmlReader.loadBeanDefinitions("file:" + strCoreContextOverrideFile);
        } else {
            AppLogService.debug("No core_context override found");
        }

        // load plugins overrides
        String strConfPluginsOverridePath = strConfPath + DIR_OVERRIDE_PLUGINS;
        File dirConfOverridePlugins = new File(strConfPluginsOverridePath);

        if (dirConfOverridePlugins.exists()) {
            String[] filesOverrideContext = dirConfOverridePlugins.list(filterContext);
            loadContexts(filesOverrideContext, strConfPluginsOverridePath, xmlReader);
        }

        gwac.refresh();

        _context = gwac;

        AppLogService.info("Spring context loaded in " + (new Date().getTime() - dateBegin.getTime()) + "ms");
    } catch (Exception e) {
        AppLogService.error("Error initializing Spring Context Service " + e.getMessage(), e);
        throw new LuteceInitException("Error initializing Spring Context Service", e);
    }
}

From source file:org.alfresco.repo.web.util.AbstractJettyComponent.java

protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent) {
    GenericWebApplicationContext wac = (GenericWebApplicationContext) BeanUtils
            .instantiateClass(GenericWebApplicationContext.class);

    // Assign the best possible id value.
    wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + contextPath);

    wac.setParent(parent);/* w w w . j a  v  a2  s. c o m*/
    wac.setServletContext(sc);
    wac.refresh();

    return wac;
}