四、复杂装配
(1)、自动装配 :容器依照一些规则去装配bean中的一个属性
      自动装配只对对象类型起作用,对基本类型不起作用
autoWrite = "byName" 按照名字去自动装配 ,根据属性名去自动装配
则配置文件中的id应该和Bean中的属性名一样
autoWrite = "byType" 根据属性的类型去匹配
autoWrite = "constructor" 根据构造器的参数类型去匹配
autoWrite = "autoDetect" 自动检测 
例子:
public class SomeBean {
 //自动装配
private String str2;
private OtherBean ob;
public SomeBean(OtherBean ob) {
super();
this.ob = ob;
}
public String getStr2() {
return str2;
}
public void setStr2(String str2) {
this.str2 = str2;
}
public OtherBean getOb() {
return ob;
}
public void setOb(OtherBean ob) {
this.ob = ob;
}
public void printInfo(){
System.out.println("str2 "+str2 +" ob "+ob);
}
}
public class OtherBean {
//自动装配
private String str1;
public String getStr1() {
return str1;
}
public void setStr1(String str1) {
this.str1 = str1;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "str1 "+str1;
}  
}
配置文件的写法
<bean id="otherBean" class="ioc5.OtherBean">
<property name="str1" value="String1" />
</bean>
<!--  <bean id="someBean" class="ioc5.SomeBean" autowire="byName">
<property name="str2" value="String2" />
</bean>
 <bean id="someBean" class="ioc5.SomeBean" autowire="byType">
<property name="str2" value="String2" />
</bean>
 -->
  <bean id="someBean" class="ioc5.SomeBean" autowire="constructor">
<property name="str2" value="String2" />
</bean>
1、自动装配的优先级低于手动装配
自动装配一般用于快速开发建立系统原型的情况,但是在正式的开发中很少使用,因为容易出错,难以维护;