可以在bean自己内调用
MoocApplicationContext context(或ApplicationContext) = (MoocApplicationContext) applicationContext.getBean("moocApplicationContext");
text.say();
MoocApplicationContext context(或ApplicationContext) = (MoocApplicationContext) applicationContext.getBean("moocApplicationContext");
text.say();
2018-04-11
2.实现ApplicationContextAware接口 就有setApplicationContext()方法,传入ApplicationContext参数
该参数相当于获取了ioc容器
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/imooc/aware/spring-aware.xml");
context == ApplicationContext传入的参数
该参数相当于获取了ioc容器
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/imooc/aware/spring-aware.xml");
context == ApplicationContext传入的参数
2018-04-11
不用junit
直接获取
ApplicationContext context = new ClassPathXmlApplicationContext("com/imooc/injection/spring-injection.xml");
InjectionService in = (InjectionService)context.getBean("injectionService");
in.save("imooc");
直接获取
ApplicationContext context = new ClassPathXmlApplicationContext("com/imooc/injection/spring-injection.xml");
InjectionService in = (InjectionService)context.getBean("injectionService");
in.save("imooc");
2018-04-10
//构造器注入-》spring将InjectionDAO实例 并赋值到 service层
//spring注入相当于帮我们实例化了injectionDAO
public InjectionServiceImpl(InjectionDAO injectionDAO1) {
this.injectionDAO = injectionDAO1;
}
//spring注入相当于帮我们实例化了injectionDAO
public InjectionServiceImpl(InjectionDAO injectionDAO1) {
this.injectionDAO = injectionDAO1;
}
2018-04-10
面向接口的编程
先接口在实例
InjectionService-》InjectionServiceImp
InjectionDAO-》InjectionDAOImpl
---------------------------------------------
也就是说,先找到接口,接口里面有方法,但是没有具体的实现内容。
所以在spring-injection.xml定义接口具体的使用方法
<bean id="injectionDAO" class="com.imooc.ioc.injection.dao.InjectionDAOImpl"></bean>
id-》接口,class:具体方法
先接口在实例
InjectionService-》InjectionServiceImp
InjectionDAO-》InjectionDAOImpl
---------------------------------------------
也就是说,先找到接口,接口里面有方法,但是没有具体的实现内容。
所以在spring-injection.xml定义接口具体的使用方法
<bean id="injectionDAO" class="com.imooc.ioc.injection.dao.InjectionDAOImpl"></bean>
id-》接口,class:具体方法
2018-04-10
顺序:
testSetter()-》(spring-injection.xml-》调用InjectionServiceImpl-》查找接口injectionDAO-》在在接口里面查找save方法com.imooc.ioc.injection.dao.InjectionDAOImpl-发回对象的方法)以injectionDAO.save()出现-》也即是service.save
testSetter()-》(spring-injection.xml-》调用InjectionServiceImpl-》查找接口injectionDAO-》在在接口里面查找save方法com.imooc.ioc.injection.dao.InjectionDAOImpl-发回对象的方法)以injectionDAO.save()出现-》也即是service.save
2018-04-10
感觉老师就顾着自己说,讲的过程根本不理会对方懂不懂,其实听这些课须具备一定基础,不然听了也是白听。
2018-04-08