BeanFactoryAware example tested

This commit is contained in:
mherbaghinyan 2018-04-29 11:26:56 +04:00
parent 5dc1b18c29
commit 2146aa2be1
3 changed files with 12 additions and 2 deletions

View File

@ -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();
}
}

View File

@ -10,4 +10,9 @@ public class Config {
public MyBeanName getMyBeanName() {
return new MyBeanName();
}
@Bean
public MyBeanFactory getMyBeanFactory() {
return new MyBeanFactory();
}
}

View File

@ -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"));
}
}