List of usage examples for org.springframework.beans.factory BeanDefinitionStoreException BeanDefinitionStoreException
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg)
From source file:com.trigonic.utils.spring.beans.ImportHelper.java
private static void importRelativeResource(XmlBeanDefinitionReader reader, Resource sourceResource, String location, Set<Resource> actualResources) { int importCount = 0; try {/*from w w w .ja v a 2s .c om*/ Resource relativeResource = sourceResource.createRelative(location); if (relativeResource.exists()) { importCount = reader.loadBeanDefinitions(relativeResource); actualResources.add(relativeResource); } } catch (IOException e) { throw new BeanDefinitionStoreException("Could not resolve current location [" + location + "]", e); } if (logger.isDebugEnabled()) { logger.debug("Imported " + importCount + " bean definitions from relative location [" + location + "]"); } }
From source file:com.brienwheeler.lib.spring.beans.SmartXmlBeanDefinitionReader.java
@Override public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException { String canonicalPath = null;/*from ww w . j ava 2s . c o m*/ try { canonicalPath = encodedResource.getResource().getURL().getPath(); } catch (IOException e) { // on FileNotFoundException, fall through to normal behavior -- this will probably result in a // FNFE from somewhere else that will make more sense. if (!(e instanceof FileNotFoundException)) throw new BeanDefinitionStoreException("Error resolving canonical path for context resource", e); } if (canonicalPath != null && loadedPaths.contains(canonicalPath)) { if (logger.isDebugEnabled()) logger.debug("skipping already loaded path " + canonicalPath); return 0; } else { int count = super.loadBeanDefinitions(encodedResource); if (canonicalPath != null) loadedPaths.add(canonicalPath); return count; } }
From source file:com.github.yihtserns.spring.groovy.GroovyBeanDefinitionReader.java
@Override public int loadBeanDefinitions(final Resource resource) throws BeanDefinitionStoreException { final Map<String, Object> vars = new HashMap<String, Object>(); try {/*from w w w . j a va 2s .com*/ final Script script = new GroovyShell().parse(new InputStreamReader(resource.getInputStream())); script.setBinding(new Binding(vars)); GroovyCategorySupport.use(SpringCategory.class, new Closure(null) { public void doCall() throws IOException { script.run(); } }); BeanDefinitionRegistry registry = getRegistry(); int beanCount = 0; for (Map.Entry<String, Object> entry : vars.entrySet()) { String varName = entry.getKey(); Object varValue = entry.getValue(); if (varValue instanceof BeanDefinition) { beanCount++; registry.registerBeanDefinition(varName, (BeanDefinition) varValue); } } return beanCount; } catch (CompilationFailedException ex) { throw new BeanDefinitionStoreException("Unable to load Groovy script", ex); } catch (IOException ex) { throw new BeanDefinitionStoreException("Unable to load resource", ex); } }
From source file:org.jboss.spring.factory.NamedXmlBeanFactory.java
private void initializeNames(Resource resource) { try {/*from w w w .j a v a 2 s. c om*/ XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new NamespaceContext() { @Override public String getNamespaceURI(String prefix) { return "http://www.springframework.org/schema/beans"; } @Override public String getPrefix(String namespaceURI) { return "beans"; } @Override public Iterator getPrefixes(String namespaceURI) { return Collections.singleton("beans").iterator(); } }); String expression = "/beans:beans/beans:description"; InputSource inputSource = new InputSource(resource.getInputStream()); String description = xPath.evaluate(expression, inputSource); if (description != null) { Matcher bfm = Pattern.compile(Constants.BEAN_FACTORY_ELEMENT).matcher(description); if (bfm.find()) { this.name = bfm.group(1); } Matcher pbfm = Pattern.compile(Constants.PARENT_BEAN_FACTORY_ELEMENT).matcher(description); if (pbfm.find()) { String parentName = pbfm.group(1); try { this.setParentBeanFactory((BeanFactory) Util.lookup(parentName, BeanFactory.class)); } catch (Exception e) { throw new BeanDefinitionStoreException( "Failure during parent bean factory JNDI lookup: " + parentName, e); } } Matcher inst = Pattern.compile(Constants.INSTANTIATION_ELEMENT).matcher(description); if (inst.find()) { instantiate = Boolean.parseBoolean(inst.group(1)); } } if (this.name == null || "".equals(StringUtils.trimAllWhitespace(this.name))) { this.name = this.defaultName; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.trigonic.utils.spring.beans.ImportHelper.java
private static void importAbsoluteResourcePattern(XmlBeanDefinitionReader reader, String location, Set<Resource> actualResources, ResourcePatternResolver resourceLoader) { try {/*ww w.j a va 2 s . c om*/ List<Resource> resources = new ArrayList<Resource>( Arrays.asList(resourceLoader.getResources(location))); int loadCount = 0; for (Resource resource : resources) { if (resource.exists()) { loadCount += reader.loadBeanDefinitions(resource); actualResources.add(resource); } } if (logger.isDebugEnabled()) { logger.debug("Loaded " + loadCount + " bean definitions from location pattern [" + location + "]"); } } catch (IOException ex) { throw new BeanDefinitionStoreException( "Could not resolve bean definition resource pattern [" + location + "]", ex); } }
From source file:org.jboss.spring.factory.NamedXmlApplicationContext.java
private void initializeNames(Resource resource) { try {/*from w w w . j av a2 s .co m*/ XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new NamespaceContext() { @Override public String getNamespaceURI(String prefix) { return "http://www.springframework.org/schema/beans"; } @Override public String getPrefix(String namespaceURI) { return "beans"; } @Override public Iterator getPrefixes(String namespaceURI) { return Collections.singleton("beans").iterator(); } }); String expression = "/beans:beans/beans:description"; InputSource inputSource = new InputSource(resource.getInputStream()); String description = xPath.evaluate(expression, inputSource); if (description != null) { Matcher bfm = Pattern.compile(Constants.BEAN_FACTORY_ELEMENT).matcher(description); if (bfm.find()) { this.name = bfm.group(1); } Matcher pbfm = Pattern.compile(Constants.PARENT_BEAN_FACTORY_ELEMENT).matcher(description); if (pbfm.find()) { String parentName = pbfm.group(1); try { this.getBeanFactory() .setParentBeanFactory((BeanFactory) Util.lookup(parentName, BeanFactory.class)); } catch (Exception e) { throw new BeanDefinitionStoreException( "Failure during parent bean factory JNDI lookup: " + parentName, e); } } } if (this.name == null || "".equals(StringUtils.trimAllWhitespace(this.name))) { this.name = this.defaultName; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.redisson.spring.cache.RedissonSpringCacheManager.java
@Override public void afterPropertiesSet() throws Exception { if (configLocation == null) { return;/* www. j av a 2 s . c om*/ } Resource resource = resourceLoader.getResource(configLocation); try { this.configMap = CacheConfig.fromJSON(resource.getInputStream()); } catch (IOException e) { // try to read yaml try { this.configMap = CacheConfig.fromYAML(resource.getInputStream()); } catch (IOException e1) { throw new BeanDefinitionStoreException( "Could not parse cache configuration at [" + configLocation + "]", e1); } } }
From source file:com.gzj.tulip.jade.context.spring.JadeComponentProvider.java
/** * jar?JadeDAO?/* w ww. j a v a 2s . com*/ * <p> * ?BeanDefinition?DAO?? * {@link BeanDefinition#getBeanClassName()} DAO??? * <p> * BeanDefinition??Spring??? */ public Set<BeanDefinition> findCandidateComponents(String uriPrefix) { if (!uriPrefix.endsWith("/")) { uriPrefix = uriPrefix + "/"; } Set<BeanDefinition> candidates = new LinkedHashSet<BeanDefinition>(); try { String packageSearchPath = uriPrefix + this.resourcePattern; boolean traceEnabled = logger.isDebugEnabled(); boolean debugEnabled = logger.isDebugEnabled(); Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath); if (debugEnabled) { logger.debug("[jade/find] find " + resources.length + " resources for " + packageSearchPath); } for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; if (traceEnabled) { logger.trace("[jade/find] scanning " + resource); } // resourcePatternResolver.getResources?classPathResourcesmetadataReadergetInputStreamnull // ???exists if (!resource.exists()) { if (debugEnabled) { logger.debug("Ignored because not exists:" + resource); } } else if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); if (isCandidateComponent(metadataReader)) { ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader); sbd.setResource(resource); sbd.setSource(resource); if (sbd.getMetadata().isInterface() && sbd.getMetadata().isIndependent()) { if (debugEnabled) { logger.debug("Identified candidate component class: " + resource); } candidates.add(sbd); } else { if (traceEnabled) { logger.trace("Ignored because not a interface top-level class: " + resource); } } } else { if (traceEnabled) { logger.trace("Ignored because not matching any filter: " + resource); } } } else { if (traceEnabled) { logger.trace("Ignored because not readable: " + resource); } } } } catch (IOException ex) { throw new BeanDefinitionStoreException("I/O failure during jade scanning", ex); } return candidates; }
From source file:de.codesourcery.spring.contextrewrite.ContextRewritingBootStrapper.java
@Override public void setBootstrapContext(final BootstrapContext ctx) { final RewriteConfig config = new AnnotationParser().parse(ctx.getTestClass()); final XMLRewrite rewrite = new XMLRewrite(); super.setBootstrapContext(new BootstrapContext() { @Override/* ww w.j ava 2s . co m*/ public Class<?> getTestClass() { return ctx.getTestClass(); } @Override public CacheAwareContextLoaderDelegate getCacheAwareContextLoaderDelegate() { return new CacheAwareContextLoaderDelegate() { @Override public ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration) { final MergedContextConfiguration wrapper = new MergedContextConfiguration( mergedContextConfiguration) { @Override public ContextLoader getContextLoader() { return new AbstractGenericContextLoader() { @Override protected BeanDefinitionReader createBeanDefinitionReader( GenericApplicationContext context) { final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader( context) { private int loadBeanDefinitions() { try { return super.loadBeanDefinitions(new EncodedResource( rewrite.filterResource(config.getResource(), config))); } catch (Exception e) { throw new BeanDefinitionStoreException( "Failed to load from classpath:" + config.getContextPath(), e); } } @Override public int loadBeanDefinitions(String location) throws BeanDefinitionStoreException { return loadBeanDefinitions((EncodedResource) null); } @Override public int loadBeanDefinitions(String location, Set<Resource> actualResources) throws BeanDefinitionStoreException { if (StringUtils.isBlank(location)) { return loadBeanDefinitions(); } return super.loadBeanDefinitions(location, actualResources); } @Override public int loadBeanDefinitions(String... locations) throws BeanDefinitionStoreException { return loadBeanDefinitions(); } public int loadBeanDefinitions(InputSource inputSource) throws BeanDefinitionStoreException { return loadBeanDefinitions(); } public int loadBeanDefinitions(InputSource inputSource, String resourceDescription) throws BeanDefinitionStoreException { return loadBeanDefinitions(); } }; return reader; } @Override protected String getResourceSuffix() { return ".xml"; } }; } }; return ctx.getCacheAwareContextLoaderDelegate().loadContext(wrapper); } @Override public void closeContext(MergedContextConfiguration mergedContextConfiguration, HierarchyMode hierarchyMode) { ctx.getCacheAwareContextLoaderDelegate().closeContext(mergedContextConfiguration, hierarchyMode); } }; } }); }
From source file:com.wantscart.jade.core.JadeDaoComponentProvider.java
/** * Scan the class path for candidate components. * //w ww . j a v a2s. c o m * basePackage the package to check for annotated classes * a corresponding Set of autodetected bean definitions */ public Set<BeanDefinition> findCandidateComponents(String uriPrefix) { if (!uriPrefix.endsWith("/")) { uriPrefix = uriPrefix + "/"; } Set<BeanDefinition> candidates = new LinkedHashSet<BeanDefinition>(); try { String packageSearchPath = uriPrefix + this.resourcePattern; boolean traceEnabled = logger.isDebugEnabled(); boolean debugEnabled = logger.isDebugEnabled(); Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath); if (debugEnabled) { logger.debug("[jade/find] find " + resources.length + " resources for " + packageSearchPath); } for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; if (traceEnabled) { logger.trace("[jade/find] scanning " + resource); } // resourcePatternResolver.getResources?classPathResourcesmetadataReadergetInputStreamnull // ???exists if (!resource.exists()) { if (debugEnabled) { logger.debug("Ignored because not exists:" + resource); } } else if (resource.isReadable()) { MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource); if (isCandidateComponent(metadataReader)) { ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader); sbd.setResource(resource); sbd.setSource(resource); if (isCandidateComponent(sbd)) { if (debugEnabled) { logger.debug("Identified candidate component class: " + resource); } candidates.add(sbd); } else { if (traceEnabled) { logger.trace("Ignored because not a interface top-level class: " + resource); } } } else { if (traceEnabled) { logger.trace("Ignored because not matching any filter: " + resource); } } } else { if (traceEnabled) { logger.trace("Ignored because not readable: " + resource); } } } } catch (IOException ex) { throw new BeanDefinitionStoreException("I/O failure during jade scanning", ex); } return candidates; }