BeanDefinition和Registry
image.png
@Test
public void testBeanDefinitionRegistry() {
//创建一个简单注册器
BeanDefinitionRegistry register = new DefaultListableBeanFactory();
//创建bean定义读取器
BeanDefinitionReader BeanDefinitionReader = new XmlBeanDefinitionReader(register);
//加载配置文件
BeanDefinitionReader.loadBeanDefinitions("bean1.xml");
//所有注册bean
System.out.println(register.getBeanDefinitionNames().length);
//从注册器获得bean定义
BeanDefinition emp = register.getBeanDefinition("emp");//根据beanName
System.out.println(emp);
BeanDefinition beanDefinition = new RootBeanDefinition(User.class);
register.registerBeanDefinition("user",beanDefinition);
System.out.println(register.getBeanDefinitionNames().length);
System.out.println(register.getBeanDefinition("user"));
}
本文标题:BeanDefinition和Registry
本文链接:https://www.haomeiwen.com/subject/qpwfpktx.html
网友评论