title: Can not find jndi datasource when deploying spring3+hibernate J2EE application to JBoss 6
body: <p>I have a J2EE application which uses Spring 3.0 + latest version of Hibernate (3.6) and I want to deploy it on JBoss 6 CR1.</p>
  
  <p>But I came across an exception stating that the datasource is not found when I deployed the application.</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920) [:3.0.5.RELEASE]
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789) [:3.0.5.RELEASE]
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) [:3.0.5.RELEASE]
   at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [:3.0.5.RELEASE]
   at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [:3.0.5.RELEASE]
   ... 159 more
  </code></pre>
  
  <p>I have checked the JMX console of JBoss Application Server and the datasource I declared in Spring is under java namespace.</p>
  
  <p>I delcared the datasource in my application-context.xml as </p>
  
  <pre><code>&lt;jee:jndi-lookup id="dataSource" jndi-name="java:ThisIsMyDataSource"/&gt;
  </code></pre>
  
  <p>In persistence.xml file I declared:</p>
  
  <pre><code>&lt;persistence-unit name="persistenceUnit" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;java:/ThisIsMyDataSource&lt;/jta-data-source&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>A datasource with a name called ThisIsMyDataSource is in the deploy folder of /jboss/server/default/deploy</p>
  
  <p>It looks like my application was trying to look for the bean for javax.sql.datasource to autowire into some other classes' constructors and failed.</p>
  
  <p>Does anyone know how to resolve this?</p>