代码示例:
public static void main(String[] args) {
//创建一个工厂对象
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
//创建一个读取器(读xml文件)
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
//读取配置文件给工厂
reader.loadBeanDefinitions("beans.xml");
//根据id获取Bean对象
UserService userService = (UserService) beanFactory.getBean("userService");
//System.out.println(userService);
UserDao userDao = (UserDao) beanFactory.getBean("userDao");
//System.out.println(userDao);
}
标签:userDao,入门,beanFactory,spring,BeanFactory,getBean,userService From: https://www.cnblogs.com/gagaya2/p/17801195.html