applicationContext对象
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) ctx.getBean("userService");
userService.save();
applicationContext对象 是在程序中 new出来的
是通过ClassPathXmlApplicationContext对象,将applicationContext.xml配置文件读取,获取到文件里的信息将它封装到applicationContext对象。
然后通过getBean(“userService”);方法找到配置文件中id值是userService的 class属性值这就得到了userService实体类对象,
这里用的是userService实体类的父类接口接受。这样就能通过userService调用service层的方法
ApplicationContext是个接口,ClassPathXmlApplicationContext是ApplicationContext接口下的子类
1.ApplicationContext是一个接口,提供了访问spring容器的API</