title: autowiring jee-jdni-lookup datasource entry in spring-config to @repository dao impl class
body: <p>I am using @repository annotation for DAO impl classes but not able to @autowire or @resource the datasource defined in beanRefContext.xml configuration as 
  jee:jndi-lookup tag </p>
  
  <p>I have all the required tag entries in place, like annotation and component package scan</p>
  
  <pre><code>&lt;jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName"
      cache="true" resource-ref="true" lookup-on-startup="false"
      proxy-interface="javax.sql.DataSource" /&gt; 
  </code></pre>
  
  <p>I tried following in @Repository impl class,</p>
  
  <pre><code>@Resource(mappedName="jdbc/xyzName")
  private DataSource dataSource;
  
  @Resource(name="datasource")
  private DataSource dataSource;
  
  @Autowired
  private DataSource dataSource;
  </code></pre>
  
  <p>Please help!</p>
  
  <pre><code>######### Main xml file ##########
  &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:jee="http://www.springframework.org/schema/jee"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
             http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"&gt;
       &lt;!-- This will automatically declare several post-processors
            including the AutowiredAnnotationBeanPostProcessor --&gt;      
       &lt;context:annotation-config/&gt;
       &lt;context:component-scan base-package="com.domain"/&gt;
       &lt;bean id="context" lazy-init="true"
          class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
          &lt;constructor-arg value="ejbBeans.xml" /&gt; 
      &lt;/bean&gt;     
  &lt;/beans&gt;
  
  ########## EJB beans xml file ################
  
  &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:jee="http://www.springframework.org/schema/jee"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd 
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"&gt;
  
      &lt;tx:annotation-driven transaction-manager="someTransactionManager" /&gt;
      &lt;bean
          class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"&gt;
          &lt;property name="alwaysUseJndiLookup" value="true" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="someTransactionManager"
          class="org.springframework.transaction.jta.WebSphereUowTransactionManager"&gt;
      &lt;/bean&gt;
  
      &lt;jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName"
          cache="true" resource-ref="true" lookup-on-startup="false"
          proxy-interface="javax.sql.DataSource" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Now getting below exception java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required..the below is the code for my DAOImpl class     </p>
  
  <p>@Repository
  public class UtilityDAOImpl extends JdbcDaoSupport implements
          UtilityDAO {
      final String className = UtilityDAOImpl.class.getName();</p>
  
  <pre><code>private JdbcTemplate jdbcTemplate ;
  
  @Autowired
  @Qualifier("dataSource")
  public void setJdbcTemplate(DataSource dataSource) {
      this.jdbcTemplate = new JdbcTemplate(dataSource);
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Got this exception</p>
  
  <pre><code>; nested exception is: org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
  org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
      at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:386)
      at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:160)
      at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:141)
      at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:121)
      at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:95)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
      at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:566)
      at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:264)
      at com.ibm.ejs.container.SessionBeanO.callPostConstructInterceptors(SessionBeanO.java:260)
      at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:409)
      at com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:45)
      at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1031)
      at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1141)
      at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:84)
      at com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:599)
      at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3964)
      at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3349)
      at com..domain.ejb.facade.EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.processRequest(EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.java)
      at com..domain.ejb.facade._EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.processRequest(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java)
      at com..domain.ejb.facade._EJSRemote0SLRequestDelegatorFacad_35bfd46c_Tie._invoke(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java)
      at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622)
      at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475)
      at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
      at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
      at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2841)
      at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2714)
      at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
      at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com.domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:143)
      at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:381)
      ... 32 more
  </code></pre>
  
  <p>And the class in question</p>
  
  <pre><code>@Repository
  public class TempUtilityDAOImpl extends JdbcDaoSupport implements
          TempUtilityDAO {
      final String className = TempUtilityDAOImpl.class.getName();
  
      private JdbcTemplate jdbcTemplate ;
  
      @Autowired
      @Qualifier("dataSource")
      public void setJdbcTemplate(DataSource dataSource) {
          this.jdbcTemplate = new JdbcTemplate(dataSource);
      }
  
      private static String IS_DEALER_IN_Temp = "select count(id_dlr) from "
              + TempConstants.DB_NAME_Temp + "V_Temp_DLR where id_dlr = ? with UR";
  
  
              /**
       * Method verifies that Dealer is not an Canadian dealer.
       * 
       * @param dealerID
       * @return
       * @throws TempSystemException
       */
      public boolean verifyTempDealer(String dealerID) throws TempSystemException {
  
          boolean isTempDealer = false;
          final String methodName = "verifyTempDealer(String dealerID)";
          MSLog.debug(className, "Exiting Method : " + methodName);
          int rowcount = getJdbcTemplate().queryForInt(IS_DEALER_IN_Temp,
                  dealerID);
  
          if (rowcount &gt; 0) {
              isTempDealer = true;
          }
  
          MSLog.debug(className, "Exiting Method : " + methodName);
          return isTempDealer;
      }
  }
  </code></pre>