use of cn.taketoday.beans.factory.InitializationBeanPostProcessor in project today-infrastructure by TAKETODAY.
the class AnnoTestBean method nullReturningBeanPostProcessor.
@Test
void nullReturningBeanPostProcessor() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(AutowiredConfig.class);
context.getBeanFactory().addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
return (bean instanceof AnnoTestBean ? null : bean);
}
});
context.getBeanFactory().addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
bean.getClass().getName();
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
bean.getClass().getName();
return bean;
}
});
context.refresh();
}
use of cn.taketoday.beans.factory.InitializationBeanPostProcessor in project today-framework by TAKETODAY.
the class StandardApplicationContextTests method nullReturningBeanPostProcessor.
@Test
void nullReturningBeanPostProcessor() {
StandardApplicationContext context = new StandardApplicationContext();
context.register(AutowiredConfig.class);
context.getBeanFactory().addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
return (bean instanceof TestBean ? null : bean);
}
});
context.getBeanFactory().addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
bean.getClass().getName();
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
bean.getClass().getName();
return bean;
}
});
context.refresh();
}
use of cn.taketoday.beans.factory.InitializationBeanPostProcessor in project today-framework by TAKETODAY.
the class XmlListableBeanFactoryTests method setup.
@BeforeEach
public void setup() {
parent = new StandardBeanFactory();
Map map = new HashMap();
map.put("name", "Albert");
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(new PropertyValues(map));
parent.registerBeanDefinition("father", bd1);
map = new HashMap();
map.put("name", "Roderick");
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(new PropertyValues(map));
parent.registerBeanDefinition("rod", bd2);
this.factory = new StandardBeanFactory(parent);
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(new ClassPathResource("test.xml", getClass()));
this.factory.addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof TestBean) {
((TestBean) bean).setPostProcessed(true);
}
if (bean instanceof DummyFactory) {
((DummyFactory) bean).setPostProcessed(true);
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean;
}
});
this.factory.addBeanPostProcessor(new LifecycleBean.PostProcessor());
this.factory.addBeanPostProcessor(new ProtectedLifecycleBean.PostProcessor());
// this.factory.preInstantiateSingletons();
}
use of cn.taketoday.beans.factory.InitializationBeanPostProcessor in project today-framework by TAKETODAY.
the class AnnoTestBean method nullReturningBeanPostProcessor.
@Test
void nullReturningBeanPostProcessor() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(AutowiredConfig.class);
context.getBeanFactory().addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
return (bean instanceof AnnoTestBean ? null : bean);
}
});
context.getBeanFactory().addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
bean.getClass().getName();
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
bean.getClass().getName();
return bean;
}
});
context.refresh();
}
use of cn.taketoday.beans.factory.InitializationBeanPostProcessor in project today-infrastructure by TAKETODAY.
the class XmlListableBeanFactoryTests method setup.
@BeforeEach
public void setup() {
parent = new StandardBeanFactory();
Map map = new HashMap();
map.put("name", "Albert");
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(new PropertyValues(map));
parent.registerBeanDefinition("father", bd1);
map = new HashMap();
map.put("name", "Roderick");
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(new PropertyValues(map));
parent.registerBeanDefinition("rod", bd2);
this.factory = new StandardBeanFactory(parent);
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(new ClassPathResource("test.xml", getClass()));
this.factory.addBeanPostProcessor(new InitializationBeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof TestBean) {
((TestBean) bean).setPostProcessed(true);
}
if (bean instanceof DummyFactory) {
((DummyFactory) bean).setPostProcessed(true);
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean;
}
});
this.factory.addBeanPostProcessor(new LifecycleBean.PostProcessor());
this.factory.addBeanPostProcessor(new ProtectedLifecycleBean.PostProcessor());
// this.factory.preInstantiateSingletons();
}
Aggregations