use of org.springframework.context.annotation.ConfigurationClassPostProcessor in project spring-framework by spring-projects.
the class ConfigurationClassProcessingTests method initBeanFactory.
/**
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition}
* for each of the given {@link Configuration} {@code configClasses}, and then
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
* When complete, the factory is ready to service requests for any {@link Bean} methods
* declared by {@code configClasses}.
*/
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
for (Class<?> configClass : configClasses) {
String configBeanName = configClass.getName();
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
}
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
ccpp.postProcessBeanDefinitionRegistry(factory);
ccpp.postProcessBeanFactory(factory);
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
rapp.setBeanFactory(factory);
factory.addBeanPostProcessor(rapp);
factory.freezeConfiguration();
return factory;
}
use of org.springframework.context.annotation.ConfigurationClassPostProcessor in project spring-framework by spring-projects.
the class ConfigurationClassAspectIntegrationTests method assertAdviceWasApplied.
private void assertAdviceWasApplied(Class<?> configClass) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
GenericApplicationContext ctx = new GenericApplicationContext(factory);
ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass));
ctx.refresh();
TestBean testBean = ctx.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("name"));
testBean.absquatulate();
assertThat(testBean.getName(), equalTo("advisedName"));
}
use of org.springframework.context.annotation.ConfigurationClassPostProcessor in project spring-framework by spring-projects.
the class ImportTests method processConfigurationClasses.
private DefaultListableBeanFactory processConfigurationClasses(Class<?>... classes) {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
for (Class<?> clazz : classes) {
beanFactory.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
}
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
return beanFactory;
}
use of org.springframework.context.annotation.ConfigurationClassPostProcessor in project spring-framework by spring-projects.
the class BeanAnnotationAttributePropagationTests method beanDef.
private AbstractBeanDefinition beanDef(Class<?> configClass) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("config", new RootBeanDefinition(configClass));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(factory);
return (AbstractBeanDefinition) factory.getBeanDefinition("foo");
}
use of org.springframework.context.annotation.ConfigurationClassPostProcessor in project spring-framework by spring-projects.
the class ImportTests method testProcessImportsWithAsm.
@Test
public void testProcessImportsWithAsm() {
int configClasses = 2;
int beansInClasses = 2;
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithImportAnnotation.class.getName()));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertThat(beanFactory.getBeanDefinitionCount(), equalTo(configClasses + beansInClasses));
}
Aggregations