title: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
body: <p>I was trying to get data from a MySQL database using the Spring utility <code>ResultSetExtractor</code>, but I got the following exception:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edao' defined in class path resource [applicationContext2.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [org.resultset.EmployeeDao]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1344)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
      at org.resultset.Test.main(Test.java:11)
  Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [org.resultset.EmployeeDao]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
      at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1012)
      at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:857)
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1341)
      ... 13 more
  </code></pre>
  
  <p>Employee.java</p>
  
  <pre><code>public class Employee {
  
      private int id;  
      private String name;  
      private float salary;
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public float getSalary() {
          return salary;
      }
      public void setSalary(float salary) {
          this.salary = salary;
      }
      public Employee(int id, String name, float salary) {
          super();
          this.id = id;
          this.name = name;
          this.salary = salary;
      } 
  
      public Employee()
      {
  
      }
  
  }
  </code></pre>
  
  <p>EmployeeDao.java</p>
  
  <pre><code>public class EmployeeDao {  
  private JdbcTemplate template;  
  
  public void setTemplate(JdbcTemplate template) {  
      this.template = template;  
  }  
  
  public List&lt;Employee&gt; getAllEmployees(){  
   return template.query("select * from employee",new ResultSetExtractor&lt;List&lt;Employee&gt;&gt;(){  
      @Override  
       public List&lt;Employee&gt; extractData(ResultSet rs) throws SQLException,  
              DataAccessException {  
  
          List&lt;Employee&gt; list=new ArrayList&lt;Employee&gt;();  
          while(rs.next()){  
          Employee e=new Employee();  
          e.setId(rs.getInt(1));  
          e.setName(rs.getString(2));  
          e.setSalary(rs.getInt(3));  
          list.add(e);  
          }  
          return list;  
          }  
      });  
    }  
  }  
  </code></pre>
  
  <p>Test.java </p>
  
  <pre><code>public class Test {  
  
  public static void main(String[] args) {  
    ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext2.xml");  
    EmployeeDao dao=(EmployeeDao)ctx.getBean("edao");  
    List&lt;Employee&gt; list=dao.getAllEmployees();  
  
    for(Employee e:list)  
        System.out.println(e);  
  
    }  
  
  }  
  </code></pre>
  
  <p>and applicationContext2.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
  &lt;beans  
      xmlns="http://www.springframework.org/schema/beans"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xmlns:p="http://www.springframework.org/schema/p"  
      xsi:schemaLocation="http://www.springframework.org/schema/beans  
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;  
  
  &lt;bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;  
  &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;  
  &lt;property name="url" value="jdbc:mysql://loclahost:3306/test1" /&gt;  
  &lt;property name="username" value="root" /&gt;  
  &lt;property name="password" value="" /&gt;  
  &lt;/bean&gt;  
  
  &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;  
  &lt;property name="dataSource" ref="ds"&gt;&lt;/property&gt;  
  &lt;/bean&gt;  
  
  &lt;bean id="edao" class="org.resultset.EmployeeDao"&gt;  
  &lt;property name="jdbcTemplate" ref="jdbcTemplate"&gt;&lt;/property&gt;  
  &lt;/bean&gt;  
  
  &lt;/beans&gt;  
  </code></pre>
  
  <p>These all are java files I am using. It says the setter's return type doesn't match with the getter's, but I checked it, and it is correct there.</p>