Spring自动装配(一)autowire=“no”
在Spring配置文件bean标签中的autowire属性的no参数
指:不适用自动装配,只是用ref进行装配注入
案例:使用autowire=“no”
1、创建类StudentServiceImpl,代码如下:
?
??注意:TeacherServiceImpl这个类中因为使用了autowire="no"参数,所以当引用StudentServiceImpl这个类时就要使用ref属性来指明引用的对象,ref中的参数为所引用的对象的id名。
?
4、测试类,代码如下:
package cn.zd.test;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.zd.service.TeacherServiceImpl;public class TestNO {@Testpublic void test1(){ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:app*.xml");TeacherServiceImpl teacherServiceImpl = (TeacherServiceImpl) ac.getBean("teacherServiceImpl");teacherServiceImpl.say();}}??5、运行结果:
老师的名字是:陈陈老师的学生是:张迪
------------------------
以上为自我理解,若有不足,请高手指点,谢谢.....
?