use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method postProcessorFailsOnImplicitOverrideIfOverridingIsNotAllowed.
@Test
public void postProcessorFailsOnImplicitOverrideIfOverridingIsNotAllowed() {
RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
rbd.setResource(new DescriptiveResource("XML or something"));
beanFactory.registerBeanDefinition("bar", rbd);
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
beanFactory.setAllowBeanDefinitionOverriding(false);
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
try {
pp.postProcessBeanFactory(beanFactory);
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
assertTrue(ex.getMessage().contains("bar"));
assertTrue(ex.getMessage().contains("SingletonBeanConfig"));
assertTrue(ex.getMessage().contains(TestBean.class.getName()));
}
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class PropertyResourceConfigurerIntegrationTests method testPropertyPlaceholderConfigurerWithNestedCircularReference.
@Test
public void testPropertyPlaceholderConfigurerWithNestedCircularReference() {
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "name${var}");
ac.registerSingleton("tb1", TestBean.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m}");
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
try {
ac.refresh();
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
}
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class ContextLoaderTests method testContextLoaderWithDefaultLocation.
@Test
public void testContextLoaderWithDefaultLocation() throws Exception {
MockServletContext sc = new MockServletContext("");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
try {
listener.contextInitialized(event);
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
assertTrue(ex.getCause() instanceof IOException);
assertTrue(ex.getCause().getMessage().contains("/WEB-INF/applicationContext.xml"));
}
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class ContextLoaderTests method testContextLoaderWithInvalidLocation.
@Test
public void testContextLoaderWithInvalidLocation() throws Exception {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
try {
listener.contextInitialized(event);
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
assertTrue(ex.getCause() instanceof FileNotFoundException);
}
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project disconf by knightliao.
the class ReloadingPropertyPlaceholderConfigurer method processProperties.
/**
* copy & paste, just so we can insert our own visitor.
* 启动时 进行配置的解析
*/
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
BeanDefinitionVisitor visitor = new ReloadingPropertyPlaceholderConfigurer.PlaceholderResolvingBeanDefinitionVisitor(props);
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
// .unicon.iamlabs.spring.properties file locations.
if (!(beanNames[i].equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
this.currentBeanName = beanNames[i];
try {
BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
try {
visitor.visitBeanDefinition(bd);
} catch (BeanDefinitionStoreException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
}
} finally {
currentBeanName = null;
}
}
}
StringValueResolver stringValueResolver = new PlaceholderResolvingStringValueResolver(props);
// New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
beanFactoryToProcess.resolveAliases(stringValueResolver);
// New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
beanFactoryToProcess.addEmbeddedValueResolver(stringValueResolver);
}
Aggregations