title: spring jndi datasource setup
body: <p>Hi i am trying to use jndi data source. below is the code</p>
  
  <p><strong>context.xml</strong></p>
  
  <pre><code>    &lt;Context antiJARLocking="true" path="/SpringMVCTest"&gt;
       &lt;Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" 
              maxActive="20" maxIdle="10" maxWait="10000" 
              name="jdbc/pluto" password="" 
              type="javax.sql.DataSource" 
              url="jdbc:mysql://localhost:3306/spring?zeroDateTimeBehavior=convertToNull" 
              username="pluto"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>in spring-servlet config bean is:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
              &lt;property name="jdbc/pluto" value="java:comp/env/jdbc/pluto"/&gt;
          &lt;/bean&gt;
  </code></pre>
  
  <p>i am getting this error</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'contactController': Injection of autowired
    dependencies failed; nested exception is
    org.springframework.beans.factory.BeanCreationException: Could not
    autowire field: private app.contact.service.ContactService
    app.contact.controller.ContactController.contactService; nested
    exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'contactServiceImpl': Injection of
    autowired dependencies failed; nested exception is
    org.springframework.beans.factory.BeanCreationException: Could not
    autowire field: private app.contact.dao.ContactDAO
    app.contact.service.ContactServiceImpl.contactDAO; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'contactDAOImpl': Injection of autowired
    dependencies failed; nested exception is
    org.springframework.beans.factory.BeanCreationException: Could not
    autowire field: private org.hibernate.SessionFactory
    app.contact.dao.ContactDAOImpl.sessionFactory; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'sessionFactory' defined in ServletContext
    resource [/WEB-INF/spring-servlet.xml]: Cannot resolve reference to
    bean 'dataSource' while setting bean property 'dataSource'; nested
    exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'dataSource' defined in ServletContext
    resource [/WEB-INF/spring-servlet.xml]: Error setting property values;
    nested exception is
    org.springframework.beans.NotWritablePropertyException: Invalid
    property 'jdbc/pluto' of bean class
    [org.springframework.jndi.JndiObjectFactoryBean]: Bean property
    'jdbc/pluto' is not writable or has an invalid setter method. Does the
    parameter type of the setter match the return type of the getter?
    Related cause:
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'dataSource' defined in ServletContext
    resource [/WEB-INF/spring-servlet.xml]: Error setting property values;
    nested exception is
    org.springframework.beans.NotWritablePropertyException: Invalid
    property 'jdbc/pluto' of bean class
    [org.springframework.jndi.JndiObjectFactoryBean]: Bean property
    'jdbc/pluto' is not writable or has an invalid setter method. Does the
    parameter type of the setter match the return type of the getter?</p>
  </blockquote>