Bean属性'myDataSource'不可写或具有无效的setter方法

时间:2012-10-30 07:16:06

标签: spring

在Spring bean中使用此配置获得以下错误:

<bean name="/login.htm" class="com.virtusa.web.EmployeeController">
  <property name="service" ref="service"></property>
</bean>

<bean id="service" class="com.virtusa.service.ServiceIMP">
  <property name="dao" ref="EmployeeDAO"></property>
</bean> 

<bean id="EmployeeDAO" class="com.virtusa.dao.EmployeeDAO">
  <property name="myDataSource" ref="myDataSource" />
</bean>

我的春季配置文件如下:

private DataSource myDataSource;
private JdbcTemplate jdbcTemplate;

public void setDataSource(DataSource myDataSource) {
    this.myDataSource = myDataSource;
     this.jdbcTemplate = new JdbcTemplate(myDataSource);
 }

我的道歉

1 个答案:

答案 0 :(得分:3)

由于您有property name="myDataSource",因此您的二传手需要命名为setMyDataSource(),而不是setDataSource()