<bean id="user" class="cn.itcast.pojo.User" scope="prototype">
<property name="name" value="李四"/>
<property name="home" value="美国"></property>
<property name="age" value="20"></property>
</bean>
<bean id="user1" class="cn.itcast.pojo.User" scope="prototype">
<property name="name" value="张三"/>
<property name="home" value="中国"></property>
<property name="age" value="30"></property>
</bean>
相同点
Autowired和Resource都是通过自动注入来注入bean对象
不同点
Autowired
Autowired只能通过class的类型进行对象注入如果像上图一样有两个同样类型的bean对象Autowired就会报错,找不到该用哪个对象来进行注入这时候可以通过@Qualifier(value=“user1”)来通过id的属性值来查找该用那个bean//(value属性值必须要设置,且值要与bean标签的id属性值对应)
Resource
Resource既可以用Bytype来注入bean也可以通过Byname来注入对象如果像上图那种情况只需要
@Resource(name = "user1")来进行对象注入// name属性值与其中一个实现类的bean标签的id属性值一致