这是我的applicationContext.xml
配置
<bean name="foo"
class="com.bmc.repository.HibernateCustomerRepositoryImpl">
</bean>
<bean name="customerService" class="com.bmc.service.CustomerServiceImpl" autowire="byType">
</bean>
Java代码:
public class CustomerServiceImpl implements CustomerService {
private CustomerRepository customerRepository;
public void setFoo(CustomerRepository b) {
this.customerRepository = b;
}
}
customerService bean依赖于HibernateCustomerRepositoryImpl。
所以我的问题是:
1。。spring如何将HibernateCustomerRepositoryImpl bean与CustomerService绑定?使用setter方法?
2。。如果是,Method的名称应该是什么?应该是setPropertyName还是setBeanName?
3。。Spring将如何找到setter方法?使用匹配的参数类型?
答案 0 :(得分:0)
<bean name="foo" id="foo"
class="com.bmc.repository.HibernateCustomerRepositoryImpl">
</bean>
<bean name="customerService" class="com.bmc.service.CustomerServiceImpl" autowire="byType">
<property name="foo" ref="foo"></property>
</bean>