title: UserDetailsService implemented class is not injecting autowired field
body: <p>i'm using acegi authentication for login . when i try to compare the values from databade 
  i'm using the following class</p>
  
  <pre><code> @Transactional(readOnly = true)
      @Service
      public class CustomUserDetailsService implements UserDetailsService {
          @Autowired
          private UserDAO userdao;
      public UserDetails loadUserByUsername(String username)
                  throws UsernameNotFoundException, DataAccessException {
  com.quest.model.dto.User dbUser = userdao.searchDatabase(username);
      }
      }
  </code></pre>
  
  <p>but the autowired field is not initializing.
  But it initialized in the controller class.
  This class is mapped through spring-security 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:security="http://www.springframework.org/schema/security"
          xmlns:mvc="http://www.springframework.org/schema/mvc"
          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/security 
                  http://www.springframework.org/schema/security/spring-security.xsd
                  http://www.springframework.org/schema/mvc 
                  http://www.springframework.org/schema/mvc/spring-mvc.xsd
                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
          &lt;!-- This is where we configure Spring-Security  --&gt;
          &lt;!-- &lt;context:annotation-config /&gt;
          &lt;context:component-scan base-package="com.quest" /&gt; 
          &lt;mvc:annotation-driven /&gt; --&gt; 
          &lt;security:http auto-config="true" use-expressions="true" access-denied-page="/auth/denied" &gt;
  
              &lt;security:intercept-url pattern="/auth/home" access="permitAll"/&gt;
              &lt;security:intercept-url pattern="/admin/*" access="hasRole('ROLE_ADMIN')"/&gt;
              &lt;security:intercept-url pattern="/student/*" access="hasRole('ROLE_STUDENT')"/&gt;
              &lt;security:intercept-url pattern="/control/*" access="hasRole('ROLE_TEACHER')"/&gt;
  
              &lt;!-- &lt;security:form-login
                      login-page="/auth/home" 
                      authentication-failure-url="/auth/home?error=true" 
                      default-target-url="/control/dummyLogin"/&gt; --&gt;
              &lt;security:form-login
                      login-page="/auth/home" 
                      authentication-failure-url="/auth/home?error=true" 
                      default-target-url="/student/student"/&gt;
  
              &lt;security:logout 
                      invalidate-session="true" 
                      logout-success-url="/auth/home" 
                      logout-url="/student/logout"/&gt;
  
          &lt;/security:http&gt;
  
          &lt;!-- Declare an authentication-manager to use a custom userDetailsService --&gt;
          &lt;security:authentication-manager&gt;
                  &lt;security:authentication-provider user-service-ref="customUserDetailsService"&gt;
                          &lt;security:password-encoder ref="passwordEncoder"/&gt;
                  &lt;/security:authentication-provider&gt;
          &lt;/security:authentication-manager&gt;
  
          &lt;!-- Use a Md5 encoder since the user's passwords are stored as Md5 in the database --&gt;
          &lt;bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/&gt;
  
          &lt;!-- A custom service where Spring will retrieve users and their corresponding access levels  --&gt;
          &lt;bean id="customUserDetailsService" class="com.quest.service.CustomUserDetailsService"/&gt;
  
  
      &lt;/beans&gt;
  </code></pre>
  
  <p>this is spring-servlrt.xml    </p>
  
  <pre><code>&lt;?xml  version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:ws="http://jax-ws.dev.java.net/spring/core"   
      xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"   
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://jax-ws.dev.java.net/spring/core http://jax-ws.java.net/spring/core.xsd
          http://jax-ws.dev.java.net/spring/servlet http://jax-ws.java.net/spring/servlet.xsd"&gt;
  
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.quest.*" /&gt;   
      &lt;mvc:annotation-driven /&gt; 
      &lt;bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"&gt;
        &lt;property name="baseAddress" value="http://localhost:9999/"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jspViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="classpath:messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" /&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="packagesToScan"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.quest.model.dto&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
                  &lt;prop key="hibernate.configurationClass"&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven /&gt;
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager" depends-on="sessionFactory"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
  &lt;!--    &lt;bean id="jacksonMessageConverter"
          class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;&lt;/bean&gt; !--&gt;
      &lt;bean
          class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
          &lt;property name="messageConverters"&gt;
              &lt;list&gt;
                  &lt;ref bean="jacksonMessageConverter" /&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
       &lt;bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
                  &lt;property name="objectMapper"&gt;
                      &lt;bean class="com.quest.data.converter.HibernateAwareObjectMapper" /&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;
  
      &lt;bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
          &lt;property name="maxUploadSize" value="200000" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="seedDataInstaller" 
          class="com.quest.model.SeedData"  init-method="populateSeed"&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>and the userDAO looks like</p>
  
  <pre><code>package com.quest.model.dao; @Repository("userdao") public class UserDAO { ...}
  </code></pre>