List of usage examples for org.springframework.beans.factory.xml XmlBeanDefinitionReader getRegistry
@Override public final BeanDefinitionRegistry getRegistry()
From source file:org.walkmod.conf.providers.SpringConfigurationProvider.java
@Override public void loadBeanFactory() throws ConfigurationException { GenericApplicationContext ctx = new GenericApplicationContext(); ClassLoader currentClassLoader = configuration.getClassLoader(); if (currentClassLoader != Thread.currentThread().getContextClassLoader()) { XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); reader.setBeanClassLoader(currentClassLoader); reader.loadBeanDefinitions(new ClassPathResource(config, currentClassLoader)); Collection<PluginConfig> plugins = configuration.getPlugins(); if (plugins != null) { for (PluginConfig plugin : plugins) { String descriptorName = plugin.getArtifactId(); if (!descriptorName.startsWith("walkmod-")) { descriptorName = "walkmod-" + descriptorName; }//from w ww .j a v a 2 s. c om if (!descriptorName.endsWith("-plugin")) { descriptorName = descriptorName + "-plugin"; } reader.loadBeanDefinitions(new ClassPathResource("META-INF/walkmod/" + descriptorName + ".xml", configuration.getClassLoader())); URL url = currentClassLoader.getResource("META-INF/walkmod2/" + descriptorName + ".xml"); if (url != null) { reader.loadBeanDefinitions(new ClassPathResource( "META-INF/walkmod2/" + descriptorName + ".xml", configuration.getClassLoader())); } } } configuration.setBeanDefinitionRegistry(reader.getRegistry()); ctx.refresh(); } configuration.setBeanFactory(ctx); }
From source file:org.sakaiproject.component.impl.SakaiContextLoader.java
/** * Allows loading/override of custom bean definitions from sakai.home */*from w w w. j av a 2 s . com*/ * <p>The pattern is the 'servlet_name-context.xml'</p> * * @param servletContext current servlet context * @return the new WebApplicationContext * @throws org.springframework.beans.BeansException * if the context couldn't be initialized */ @Override public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException { ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) super.initWebApplicationContext( servletContext); // optionally look in sakai home for additional bean deifinitions to load if (cwac != null) { final String servletName = servletContext.getServletContextName(); String location = getHomeBeanDefinitionIfExists(servletName); if (StringUtils.isNotBlank(location)) { log.debug("Servlet " + servletName + " is attempting to load bean definition [" + location + "]"); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader( (BeanDefinitionRegistry) cwac.getBeanFactory()); try { int loaded = reader.loadBeanDefinitions(new FileSystemResource(location)); log.info("Servlet " + servletName + " loaded " + loaded + " beans from [" + location + "]"); AnnotationConfigUtils.registerAnnotationConfigProcessors(reader.getRegistry()); cwac.getBeanFactory().preInstantiateSingletons(); } catch (BeanDefinitionStoreException bdse) { log.warn("Failure loading beans from [" + location + "]", bdse); } catch (BeanCreationException bce) { log.warn("Failure instantiating beans from [" + location + "]", bce); } } } return cwac; }
From source file:org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.java
/** * Create a new {@code GroovyBeanDefinitionReader} based on the given * {@link XmlBeanDefinitionReader}, loading bean definitions into its * {@code BeanDefinitionRegistry} and delegating Groovy DSL loading to it. * <p>The supplied {@code XmlBeanDefinitionReader} should typically * be pre-configured with XML validation disabled. * @param xmlBeanDefinitionReader the {@code XmlBeanDefinitionReader} to * derive the registry from and to delegate Groovy DSL loading to */// w w w . ja v a2 s . com public GroovyBeanDefinitionReader(XmlBeanDefinitionReader xmlBeanDefinitionReader) { super(xmlBeanDefinitionReader.getRegistry()); this.standardXmlBeanDefinitionReader = new XmlBeanDefinitionReader(xmlBeanDefinitionReader.getRegistry()); this.groovyDslXmlBeanDefinitionReader = xmlBeanDefinitionReader; }