BeanDefinitionRegistryPostProcessors' postProcessBeanDefinitionRegistry() method now gets called before postProcessBeanFactory() (SPR-7167)

This commit is contained in:
Chris Beams
2010-05-17 16:21:36 +00:00
parent 0b8140b50d
commit 57a503b274
2 changed files with 63 additions and 5 deletions

View File

@@ -0,0 +1,58 @@
package org.springframework.context.annotation.configuration;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
public class Spr7167Tests {
@Test
public void test() {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
assertThat("someDependency was not post processed",
ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription(),
equalTo("post processed by MyPostProcessor"));
MyConfig config = ctx.getBean(MyConfig.class);
assertTrue("Config class was not enhanced", AopUtils.isCglibProxyClass(config.getClass()));
}
}
@Configuration
class MyConfig {
@Bean
public Dependency someDependency() {
return new Dependency();
}
@Bean
public BeanFactoryPostProcessor thePostProcessor() {
return new MyPostProcessor(someDependency());
}
}
class Dependency {
}
class MyPostProcessor implements BeanFactoryPostProcessor {
public MyPostProcessor(Dependency someDependency) {
}
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
AbstractBeanDefinition bd = (AbstractBeanDefinition) beanFactory.getBeanDefinition("someDependency");
bd.setDescription("post processed by MyPostProcessor");
}
}