title: Spring 3 autowire is always null
body: <p>I'm having difficultly getting what seems like a very basic auto wiring to occur. I'm trying to add another data source to our system for warehouse stuff, but I'm running in to an issue. I'm not an expert in Spring by an stretch, and I've been reading around on this issue, and it seems like I have everything setup correctly. </p>
  
  <p>I tried changing my component scan to also include the repositories, but that didn't fix the issue. I also tried @Resource with the bean name specified.</p>
  
  <p>It never throws any errors until I try to construct the jdbcTemplate since the dataSource is null.</p>
  
  <p>The other classes we have that use injection all seem to work fine, it's just this new one using the datasource injection is failing (This is the first time we're doing a datasource injection, everything else is all Domain entities, but we won't be using a traditional domain/entity for the warehouse db).</p>
  
  <p>I feel certain I'm just missing something very simple, but so far I haven't been able to find what that is.</p>
  
  <p>Just a debug repo</p>
  
  <pre><code>package com.foobar.repositories
  
  @Repository
  public class WarehouseRepository
  {
      @Autowired
      private DataSource warehouseDataSource; // This is always null
  
      private JdbcTemplate jdbcTemplate;
  
      public WarehouseRepository()
      {
          jdbcTemplate = new JdbcTemplate(warehouseDataSource);
      }
  
      public void debug()
      {
          SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foobar");
          int i = sqlRowSet.getInt(0);
          String test = sqlRowSet.getString(1);
      }
  }
  </code></pre>
  
  <p>XML Config</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:tx="http://www.springframework.org/schema/tx"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:jdbc="http://www.springframework.org/schema/jdbc"
         xmlns:jpa="http://www.springframework.org/schema/data/jpa"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
         http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd
         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
          &gt;
      &lt;context:annotation-config/&gt;
      &lt;context:component-scan base-package="com.foobar.domain"/&gt;
      &lt;context:component-scan base-package="com.foobar.services"/&gt;
  
      &lt;jpa:repositories base-package="com.foobar.repositories" /&gt;
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"&gt;&lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  
          &lt;bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="location" value="classpath:env.properties"/&gt;
          &lt;/bean&gt;
          &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                destroy-method="close"&gt;
              &lt;property name="driverClass" value="${env.driver}" /&gt;
              &lt;property name="jdbcUrl" value="${env.url}" /&gt;
              &lt;property name="user" value="${env.username}" /&gt;
              &lt;property name="password" value="${env.password}" /&gt;
              &lt;property name="minPoolSize" value="1" /&gt;
              &lt;property name="maxPoolSize" value="100" /&gt;
              &lt;property name="maxStatements" value="0" /&gt;
              &lt;property name="acquireIncrement" value="1" /&gt;
          &lt;/bean&gt;
          &lt;bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
              &lt;property name="persistenceUnitName" value="JpaPersistenceUnit" /&gt;
              &lt;property name="dataSource" ref="dataSource" /&gt;
              &lt;property name="jpaVendorAdapter"&gt;
                  &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                      &lt;property name="showSql" value="false"/&gt;
                      &lt;property name="generateDdl" value="false"/&gt;
                      &lt;property name="database" value="MYSQL"/&gt;
                  &lt;/bean&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean id="warehouseDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
              &lt;property name="driverClassName" value="${env.driver}" /&gt;
              &lt;property name="url" value="${env.warehouseUrl}" /&gt;
              &lt;property name="username" value="${env.username}" /&gt;
              &lt;property name="password" value="${env.password}" /&gt;
          &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>Sep 17, 2013 6:50:09 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [] threw exception
  java.lang.IllegalArgumentException: Property 'dataSource' is required
      at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:134)
      at org.springframework.jdbc.core.JdbcTemplate.&lt;init&gt;(JdbcTemplate.java:165)
      at com.foobar.repositories.WarehouseRepository.debug(WarehouseRepository.java:23)
      at com.services.publicServices.OrderConfirmationService.debug(OrderConfirmationService.java:79)
      at com.services.publicServices.OrderConfirmationService$$FastClassByCGLIB$$fd3be016.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:627)
      at com.services.publicServices.OrderConfirmationService$$EnhancerByCGLIB$$f00e6716.debug(&lt;generated&gt;)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
      at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
      at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
      at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
      at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
      at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
      at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
      at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
      at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>Repo method after removing the constructor</p>
  
  <pre><code>package com.foobar.repositories
  
  @Repository
  public class WarehouseRepository
  {
      @Autowired
      private DataSource warehouseDataSource; // This is always null
  
      private JdbcTemplate jdbcTemplate;   
  
      public void debug()
      {
          jdbcTemplate = new JdbcTemplate(warehouseDataSource);// Still blows up here
          SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foobar");
          int i = sqlRowSet.getInt(0);
          String test = sqlRowSet.getString(1);
      }
  }
  </code></pre>