List of usage examples for org.springframework.web.context.support GenericWebApplicationContext GenericWebApplicationContext
public GenericWebApplicationContext(DefaultListableBeanFactory beanFactory)
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 w w w .j a va2s .co 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.impalaframework.web.spring.loader.BaseImpalaContextLoader.java
/** * Instantiates Impala in the form of a <code>ModuleManagementFacade</code> instance. *///from w ww. j a v a 2 s.c o m protected ModuleManagementFacade createModuleManagementFacade(ServletContext servletContext, WebApplicationContext parent) { String[] locations = getBootstrapContextLocations(servletContext); logger.info("Loading bootstrap context from locations " + Arrays.toString(locations)); final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); final GenericWebApplicationContext applicationContext = new GenericWebApplicationContext(beanFactory); applicationContext.setServletContext(servletContext); applicationContext.setParent(parent); XmlBeanDefinitionReader definitionReader = new XmlBeanDefinitionReader(beanFactory); for (int i = 0; i < locations.length; i++) { definitionReader.loadBeanDefinitions(new ClassPathResource(locations[i])); } applicationContext.refresh(); return ObjectUtils.cast(applicationContext.getBean("moduleManagementFacade"), ModuleManagementFacade.class); }
From source file:org.impalaframework.web.spring.module.BaseWebModuleLoader.java
protected GenericWebApplicationContext newApplicationContext(ModuleDefinition moduleDefinition, ApplicationContext parent, ClassLoader classLoader, ServletContext servletContext, final DefaultListableBeanFactory beanFactory) { final GenericWebApplicationContext context = new GenericWebApplicationContext(beanFactory); context.setServletContext(servletContext); context.setClassLoader(classLoader); context.setParent(parent);/* w ww. j a v a 2s.com*/ final String displayName = ModuleLoaderUtils.getDisplayName(moduleDefinition, context); context.setDisplayName(displayName); return context; }