List of usage examples for org.springframework.beans.factory.xml ResourceEntityResolver ResourceEntityResolver
public ResourceEntityResolver(ResourceLoader resourceLoader)
From source file:org.web4thejob.context.DefaultSessionContext.java
@Override protected void loadBeanDefinitions(final DefaultListableBeanFactory beanFactory) throws BeansException, IOException { // Create a new XmlBeanDefinitionReader for the given BeanFactory. final XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); // Allow a subclass to provide custom initialization of the reader, // then proceed with actually loading the bean definitions. // initBeanDefinitionReader(beanDefinitionReader); loadBeanDefinitions(beanDefinitionReader); }
From source file:org.sakaiproject.util.SakaiApplicationContext.java
protected void loadBeanDefinitions(ConfigurableListableBeanFactory beanFactory) throws IOException { // Create a new XmlBeanDefinitionReader for the given BeanFactory. XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader( (BeanDefinitionRegistry) beanFactory); beanDefinitionReader.setBeanClassLoader(Thread.currentThread().getContextClassLoader()); beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); if (configLocations != null) { beanDefinitionReader.loadBeanDefinitions(configLocations); }// w w w .j a va 2s.co m }
From source file:com.opengamma.component.factory.AbstractSpringComponentFactory.java
/** * Creates the application context./*w w w . ja va2 s.c o m*/ * * @param repo the component repository, not null * @return the Spring application context, not null */ protected GenericApplicationContext createApplicationContext(ComponentRepository repo) { Resource springFile = getSpringFile(); try { repo.getLogger().logDebug(" Spring file: " + springFile.getURI()); } catch (Exception ex) { // ignore } DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); GenericApplicationContext appContext = new GenericApplicationContext(beanFactory); PropertyPlaceholderConfigurer properties = new PropertyPlaceholderConfigurer(); properties.setLocation(getPropertiesFile()); XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); beanDefinitionReader.setValidating(true); beanDefinitionReader.setResourceLoader(appContext); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(appContext)); beanDefinitionReader.loadBeanDefinitions(springFile); appContext.getBeanFactory().registerSingleton("injectedProperties", properties); appContext.getBeanFactory().registerSingleton("componentRepository", repo); appContext.refresh(); return appContext; }
From source file:com.brienwheeler.lib.spring.beans.SmartClassPathXmlApplicationContext.java
/** * Since this method in the parent class doesn't allow customization of the * bean definition reader class, we copy the logic here. *///from ww w.java 2s. c o m @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { // Create a new XmlBeanDefinitionReader for the given BeanFactory. XmlBeanDefinitionReader beanDefinitionReader = new SmartXmlBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); // Allow a subclass to provide custom initialization of the reader, // then proceed with actually loading the bean definitions. initBeanDefinitionReader(beanDefinitionReader); loadBeanDefinitions(beanDefinitionReader); }
From source file:net.bubble.common.utils.BeanContextUtil.java
/** * ?Spring?</br>/*from www . ja v a2 s .co m*/ * ???war/ear??????? * @param configurationLocations spring? * @throws CommonException Common? */ public void loadCustomizedConfiguration(List<String> configurationLocations) throws CommonException { logger.info("Loading custom configuration file ......"); if (configurationLocations == null || configurationLocations.size() < 1) { logger.info("No custom configuration file !"); return; } try { XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader( (BeanDefinitionRegistry) applicationContext.getBeanFactory()); beanDefinitionReader.setResourceLoader(applicationContext); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(applicationContext)); for (String localtion : configurationLocations) beanDefinitionReader.loadBeanDefinitions(applicationContext.getResources(localtion)); } catch (BeansException e) { logger.error(e.getMessage(), e); throw new CommonException("Load custom bean definitions has error !", e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new CommonException("Read configuration file has error !", e); } logger.info("Load Custom configuration file is finish !"); }
From source file:com.griddynamics.banshun.StrictContextParentBean.java
private BeanDefinitionRegistry getBeanFactory(String location) { XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader( new SimpleBeanDefinitionRegistry()); beanDefinitionReader.setResourceLoader(context); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(context)); beanDefinitionReader.loadBeanDefinitions(location); return beanDefinitionReader.getBeanFactory(); }
From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java
/** * <p>Load the template BeanDefinition and call {@link #transform(ConfigurableListableBeanFactory, BeanDefinition, Element, ParserContext)} * to apply runtime configuration value to it. <code>builder</code> will be configured to instantiate the bean * in the Spring context that we are parsing.</p> * /* ww w .ja va2 s . co m*/ * <p>During parsing, an instance of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} is pushed onto <code>ParserContext</code> so * that nested tags can access the enclosing template configuration with a call to {@link #findEnclosingTemplateFactory(ParserContext)}. * Subclasses can override {@link #newComponentDefinition(String, Object, DefaultListableBeanFactory)} to provide a * subclass of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} to the parser context if necessary.</p> */ @Override protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //if we have multiple nested bean definitions, we only parse the template factory //once. this allows configuration changes made by enclosing bean parsers to be inherited //by contained beans, which is quite useful. DefaultListableBeanFactory templateFactory = findEnclosingTemplateFactory(parserContext); TemplateComponentDefinition tcd = null; if (templateFactory == null) { //no nesting -- load the template XML configuration from the classpath. final BeanFactory parentFactory = (BeanFactory) parserContext.getRegistry(); templateFactory = new DefaultListableBeanFactory(parentFactory); //load template bean definitions DefaultResourceLoader loader = new DefaultResourceLoader(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(templateFactory); reader.setResourceLoader(loader); reader.setEntityResolver(new ResourceEntityResolver(loader)); reader.loadBeanDefinitions(templateResource); //propagate factory post-processors from the source factory into the template //factory. BeanDefinition ppChain = new RootBeanDefinition(ChainingBeanFactoryPostProcessor.class); ppChain.getPropertyValues().addPropertyValue("targetFactory", templateFactory); parserContext.getReaderContext().registerWithGeneratedName(ppChain); //push component definition onto the parser stack for the benefit of //nested bean definitions. tcd = newComponentDefinition(element.getNodeName(), parserContext.extractSource(element), templateFactory); parserContext.pushContainingComponent(tcd); } try { //allow subclasses to apply overrides to the template bean definition. BeanDefinition def = templateFactory.getBeanDefinition(templateId); transform(templateFactory, def, element, parserContext); //setup our factory bean to instantiate the modified bean definition upon request. builder.addPropertyValue("beanFactory", templateFactory); builder.addPropertyValue("beanName", templateId); builder.getRawBeanDefinition().setAttribute("id", def.getAttribute("id")); } finally { if (tcd != null) parserContext.popContainingComponent(); } }
From source file:org.solmix.runtime.support.spring.ContainerApplicationContext.java
@Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException { // Create a new XmlBeanDefinitionReader for the given BeanFactory. XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); beanDefinitionReader.setNamespaceHandlerResolver(nshResolver); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); // Allow a subclass to provide custom initialization of the reader, // then proceed with actually loading the bean definitions. initBeanDefinitionReader(beanDefinitionReader); loadBeanDefinitions(beanDefinitionReader); }
From source file:org.cloudfoundry.identity.uaa.BootstrapTests.java
private ConfigurableApplicationContext getServletContext(String... resources) { String environmentConfigLocations = "required_configuration.yml,${LOGIN_CONFIG_URL},file:${LOGIN_CONFIG_PATH}/login.yml,file:${CLOUD_FOUNDRY_CONFIG_PATH}/login.yml,${UAA_CONFIG_URL},file:${UAA_CONFIG_FILE},file:${UAA_CONFIG_PATH}/uaa.yml,file:${CLOUD_FOUNDRY_CONFIG_PATH}/uaa.yml"; String profiles = null;//w w w .java 2s . c o m String[] resourcesToLoad = resources; if (!resources[0].endsWith(".xml")) { profiles = resources[0]; resourcesToLoad = new String[resources.length - 1]; System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length); } final String[] configLocations = resourcesToLoad; AbstractRefreshableWebApplicationContext context = new AbstractRefreshableWebApplicationContext() { @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setEnvironment(this.getEnvironment()); beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); if (configLocations != null) { for (String configLocation : configLocations) { beanDefinitionReader.loadBeanDefinitions(configLocation); } } } }; MockServletContext servletContext = new MockServletContext() { @Override public RequestDispatcher getNamedDispatcher(String path) { return new MockRequestDispatcher("/"); } public String getVirtualServerName() { return null; } }; context.setServletContext(servletContext); MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("environmentConfigLocations", environmentConfigLocations); context.setServletConfig(servletConfig); YamlServletProfileInitializer initializer = new YamlServletProfileInitializer(); initializer.initialize(context); if (profiles != null) { context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles)); } context.refresh(); return context; }