BeanFactoryAware example tested
This commit is contained in:
parent
5dc1b18c29
commit
2146aa2be1
|
@ -13,5 +13,8 @@ public class AwareExample {
|
|||
= new AnnotationConfigApplicationContext(Config.class);
|
||||
|
||||
MyBeanName myBeanName = context.getBean(MyBeanName.class);
|
||||
|
||||
MyBeanFactory myBeanFactory = context.getBean(MyBeanFactory.class);
|
||||
myBeanFactory.getMyBeanName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,4 +10,9 @@ public class Config {
|
|||
public MyBeanName getMyBeanName() {
|
||||
return new MyBeanName();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MyBeanFactory getMyBeanFactory() {
|
||||
return new MyBeanFactory();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,12 @@ public class MyBeanFactory implements BeanFactoryAware {
|
|||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
|
||||
this.beanFactory = beanFactory;
|
||||
System.out.println(beanFactory);
|
||||
}
|
||||
|
||||
public void getMyBeanName() {
|
||||
MyBeanName myBeanName = beanFactory.getBean(MyBeanName.class);
|
||||
System.out.println(beanFactory.isSingleton("myCustomBeanName"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue