日期:2014-05-17  浏览次数:20775 次

ssh
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
UserManager userManager = (UserManager)context.getBean("userManager");
RoleManager roleManager = (RoleManager)context.getBean("roleManager");

其中的context.getBean("userManager");里面的userManager是什么意思?
------解决方案--------------------
就是你把UserManager类让spring管理。这就是注入
------解决方案--------------------
applicationContext.xml,这个文件代码复制上来看看
------解决方案--------------------
看看
------解决方案--------------------
1、Error creating bean with name 'userManager'
2、Error creating bean with name 'userDao' defined in file
3、Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]:
估计还是配置文件写错了吧
------解决方案--------------------
Spring的配置文件中的Bean对象的id,对它进行获取
------解决方案--------------------
这么理解吧,spring容器在初始化的时候回根据标签将这个类实例化了一个放在spring容器里,然后你getBean的时候就从容器中拿到了这个对象,就不用自己去实例化了