List of usage examples for org.springframework.context.support StaticApplicationContext getBeanFactory
@Override public final ConfigurableListableBeanFactory getBeanFactory()
From source file:net.sourceforge.vulcan.spring.SpringPluginManagerTest.java
public void testPluginAppCtxGetsParentPropertyPlaceholder() throws Exception { final PropertyResourceConfigurer cfgr = new PropertyPlaceholderConfigurer(); final StaticApplicationContext ctx = new StaticApplicationContext(); ctx.getBeanFactory().registerSingleton("foo", cfgr); ctx.refresh();/*from www.ja va 2 s . c o m*/ mgr.setApplicationContext(ctx); expect(store.getPluginConfigs()).andReturn(new PluginMetaDataDto[] { createFakePluginConfig(true) }); expert.registerPlugin((ClassLoader) anyObject(), (String) anyObject()); replay(); mgr.init(); verify(); assertTrue("should contain cfgr", mgr.plugins.get("1").context.getBeanFactoryPostProcessors().contains(cfgr)); }
From source file:io.milton.servlet.SpringMiltonFilter.java
@SuppressWarnings("resource") protected void initSpringApplicationContext(FilterConfig fc) { final WebApplicationContext rootContext = WebApplicationContextUtils .getWebApplicationContext(fc.getServletContext()); StaticApplicationContext parent; if (rootContext != null) { log.info("Found a root spring context, and using it"); parent = new StaticApplicationContext(rootContext); } else {/*from w w w . java2s . c om*/ log.info("No root spring context"); parent = new StaticApplicationContext(); } final FilterConfigWrapper configWrapper = new FilterConfigWrapper(fc); parent.getBeanFactory().registerSingleton("config", configWrapper); parent.getBeanFactory().registerSingleton("servletContext", fc.getServletContext()); File webRoot = new File(fc.getServletContext().getRealPath("/")); parent.getBeanFactory().registerSingleton("webRoot", webRoot); log.info("Registered root webapp path in: webroot=" + webRoot.getAbsolutePath()); parent.refresh(); final String configClass = fc.getInitParameter("contextConfigClass"); final String sFiles = fc.getInitParameter("contextConfigLocation"); ConfigurableApplicationContext ctx = null; if (StringUtils.isNotBlank(configClass)) { try { Class<?> clazz = Class.forName(configClass); final AnnotationConfigApplicationContext annotationCtx = new AnnotationConfigApplicationContext(); annotationCtx.setParent(parent); annotationCtx.register(clazz); annotationCtx.refresh(); ctx = annotationCtx; } catch (ClassNotFoundException e) { ctx = null; log.error("Unable to create a child context for Milton", e); } } else { String[] contextFiles; if (sFiles != null && sFiles.trim().length() > 0) { contextFiles = sFiles.split(" "); } else { contextFiles = new String[] { "applicationContext.xml" }; } try { ctx = new ClassPathXmlApplicationContext(contextFiles, parent); } catch (BeansException e) { log.error("Unable to create a child context for Milton", e); } } if (ctx == null) { log.warn("No child context available, only using parent context"); context = parent; } else { context = ctx; } }