@Test public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setClassLoader(null); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass())); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass())); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass())); ctx.refresh(); assertEquals(ObjectUtils.identityToString(ctx), ctx.getId()); assertEquals(ObjectUtils.identityToString(ctx), ctx.getDisplayName()); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); ctx.close(); }
private void loadBeanDefinitions(Resource resource, ClassLoader classLoader) { applicationContext = new GenericApplicationContext(); applicationContext.setClassLoader(classLoader); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext) { @Override protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver(); return new SpringCamelContextBootstrap.CamelNamespaceHandlerResolver(defaultResolver); } }; xmlReader.loadBeanDefinitions(resource); }
private void loadBeanDefinitions(Resource resource, ClassLoader classLoader) { applicationContext = new GenericApplicationContext(); applicationContext.setClassLoader(classLoader); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext) { @Override protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver(); return new SpringCamelContextBootstrap.CamelNamespaceHandlerResolver(defaultResolver); } }; xmlReader.loadBeanDefinitions(resource); }
private static GenericApplicationContext getGenericApplicationContext(ClassLoader classLoader) { final GenericApplicationContext genericApplicationContext = new GenericApplicationContext(); genericApplicationContext.setClassLoader(classLoader); genericApplicationContext.refresh(); genericApplicationContext.start(); return genericApplicationContext; }
public static GenericApplicationContext getSpringApplicationContextClassPath( ClassLoader classLoader, String relPath) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(classLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); InputStream in = classLoader.getResourceAsStream(relPath); if (in == null) { throw new AxisFault("Spring context cannot be located for AxisService"); } xbdr.loadBeanDefinitions(new InputStreamResource(in)); appContext.refresh(); } catch (Exception e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; }
public static GenericApplicationContext getSpringApplicationContext( String applicationContxtFilePath, ClassLoader springBeansClassLoader) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(springBeansClassLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try { // Save the class loader so that you can restore it later Thread.currentThread() .setContextClassLoader( new MultiParentClassLoader(new URL[]{}, new ClassLoader[]{ springBeansClassLoader, prevCl})); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); xbdr.loadBeanDefinitions(new InputStreamResource( new FileInputStream(new File(applicationContxtFilePath)))); appContext.refresh(); } catch (FileNotFoundException e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; }
URLClassLoader classLoader = new URLClassLoader( new URL[] { pluginUrl }, this.getClass().getClassLoader() ); GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setClassLoader( classLoader ); Resource resource = ctx.getResource( "jar:file:" + secureDeliveryPlugin + "!/spring-context.xml" );
URLClassLoader classLoader = new URLClassLoader( new URL[] { pluginUrl }, this.getClass().getClassLoader() ); GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setClassLoader( classLoader ); Resource resource = ctx.getResource( "jar:file:" + secureDeliveryPlugin + "!/spring-context.xml" );
private GenericApplicationContext createFlowApplicationContext(Resource[] resources) { ApplicationContext parent = getContext().getApplicationContext(); GenericApplicationContext flowContext; if (parent instanceof WebApplicationContext) { GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(((WebApplicationContext) parent).getServletContext()); flowContext = webContext; } else { flowContext = new GenericApplicationContext(); } flowContext.setDisplayName("Flow ApplicationContext [" + getContext().getFlowId() + "]"); flowContext.setParent(parent); flowContext.getBeanFactory().registerScope("request", new RequestScope()); flowContext.getBeanFactory().registerScope("flash", new FlashScope()); flowContext.getBeanFactory().registerScope("view", new ViewScope()); flowContext.getBeanFactory().registerScope("flow", new FlowScope()); flowContext.getBeanFactory().registerScope("conversation", new ConversationScope()); // Ensure the current ClassLoader is used, or otherwise setting the ResourceLoader would suppress it ClassLoader classLoaderToUse = flowContext.getClassLoader(); flowContext.setClassLoader(classLoaderToUse); Resource flowResource = flowModelHolder.getFlowModelResource(); flowContext.setResourceLoader(new FlowRelativeResourceLoader(flowResource)); AnnotationConfigUtils.registerAnnotationConfigProcessors(flowContext); new XmlBeanDefinitionReader(flowContext).loadBeanDefinitions(resources); registerFlowBeans(flowContext.getBeanFactory()); registerMessageSource(flowContext, flowResource); flowContext.refresh(); return flowContext; }
@Setup(Level.Invocation) public void start() { ConfigurationClassPostProcessor processor = new ConfigurationClassPostProcessor(); processor.setBeanClassLoader(MyConfiguration.class.getClassLoader()); processor.setEnvironment(new StandardEnvironment()); registry = new GenericApplicationContext(); registry.setClassLoader(MyConfiguration.class.getClassLoader()); registry.registerBean(AutowiredAnnotationBeanPostProcessor.class); registry.registerBean(MyConfiguration.class); registry.addBeanFactoryPostProcessor(processor); }
public void init(Properties configProperties, URL webappConfigURL) { mApplicationContext = new GenericApplicationContext(); mApplicationContext.setClassLoader(this.getClass().getClassLoader()); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); ppc.setProperties(configProperties); mApplicationContext.addBeanFactoryPostProcessor(ppc); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(mApplicationContext); xmlReader.loadBeanDefinitions(new UrlResource(webappConfigURL)); mApplicationContext.refresh(); mWebappDataProvider = (DataProvider) mApplicationContext.getBean("webappDataProvider"); mSkipManager = (SkipManager) mApplicationContext.getBean("skipManager"); }
applicationContext.setClassLoader(Play.classloader); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); if (Play.configuration.getProperty(PLAY_SPRING_NAMESPACE_AWARE,
applicationContext.setClassLoader(classLoader);
appContext = new GenericApplicationContext(); ClassLoader serviceCL = axisService.getClassLoader(); appContext.setClassLoader(serviceCL); ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
appContext = new GenericApplicationContext(); ClassLoader serviceCL = axisService.getClassLoader(); appContext.setClassLoader(serviceCL); ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
private GenericApplicationContext createFlowApplicationContext(Resource[] resources) { ApplicationContext parent = getContext().getApplicationContext(); GenericApplicationContext flowContext; if (parent instanceof WebApplicationContext) { GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(((WebApplicationContext) parent).getServletContext()); flowContext = webContext; } else { flowContext = new GenericApplicationContext(); } flowContext.setDisplayName("Flow ApplicationContext [" + getContext().getFlowId() + "]"); flowContext.setParent(parent); flowContext.getBeanFactory().registerScope("request", new RequestScope()); flowContext.getBeanFactory().registerScope("flash", new FlashScope()); flowContext.getBeanFactory().registerScope("view", new ViewScope()); flowContext.getBeanFactory().registerScope("flow", new FlowScope()); flowContext.getBeanFactory().registerScope("conversation", new ConversationScope()); // Ensure the current ClassLoader is used, or otherwise setting the ResourceLoader would suppress it ClassLoader classLoaderToUse = flowContext.getClassLoader(); flowContext.setClassLoader(classLoaderToUse); Resource flowResource = flowModelHolder.getFlowModelResource(); flowContext.setResourceLoader(new FlowRelativeResourceLoader(flowResource)); AnnotationConfigUtils.registerAnnotationConfigProcessors(flowContext); new XmlBeanDefinitionReader(flowContext).loadBeanDefinitions(resources); registerFlowBeans(flowContext.getBeanFactory()); registerMessageSource(flowContext, flowResource); flowContext.refresh(); return flowContext; }