1、Spring 半自动装配(手工装配)
(1)在xml文件中bean里添加属性autowire="byType",会自动帮当前bean的属性赋值,根据类型从容器中查找合适的bean来赋 值,如果本类的属性依赖的多个类,有多个值的时候会报错,如果属性依赖的类没有装配,则为null。
e.g <bean id="computerService" class="service.ComputerService" autowire="byType" />
(2) 在bean中添加属性autowire="byName",会自动根据名字从容器查找合适的bean来赋值,根据名字找不到,不会报错,值为 null;
e.g <bean id="computerService2" class="service.ComputerService" autowire="byName" />
2、Spring 全自动装配
在xml文件中添加 <context:component-scan base-package="cn.neusoft.spring"></context:component-scan>
base-package中的值要按照oracle命名规范来写,并且要提取公共的部分,这样才能扫描dao、service、controller等多层。