title: Spring and Spring security configuration help, cannot find a bean
body: <p>I keep receiving the exception with a message: "org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailsService' is defined" even though the bean is defined as a service in the UserDetailsServiceImpl class. Such as:</p>
  
  <pre><code>@Service(value="userDetailsService")
  public class UserDetailsServiceImpl implements UserDetailsService{
  </code></pre>
  
  <p>I am using the latest Spring and Spring Security. </p>
  
  <p>I am not sure what I am doing wrong. I am pasting the configuration of my spring xml files. The spring-security.xml shows that it can find beans from the servlet-context.xml when using the component-scan.</p>
  
  <p>Thank you</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.filterChains': Cannot resolve reference to bean org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean org.springframework.security.authentication.ProviderManager#0' while setting bean property authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.authenticationManager': Cannot resolve reference to bean org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailsService' is defined
  </code></pre>
  
  <p>spring-security.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
  xmlns:beans="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/security
         http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  
  &lt;beans:import resource="classpath*:servlet-context.xml"/&gt; 
  
  &lt;global-method-security secured-annotations="enabled"&gt;&lt;/global-method-security&gt;    
  
  &lt;http auto-config="true" &gt;
      &lt;!-- Filtering url patterns --&gt;
  
      &lt;!-- Anonymous users --&gt;
      &lt;intercept-url pattern="/" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
      &lt;intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" /&gt;
  
      &lt;!-- Login and logout controls --&gt;
      &lt;form-login login-page="/login" default-target-url="/profile"
          authentication-failure-url="/loginfailed" /&gt;
      &lt;logout invalidate-session="true" logout-success-url="/"
          delete-cookies="JSESSIONID" /&gt;
  
  &lt;/http&gt;
  
  &lt;beans:bean id="authenticationProvider"
      class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
      &lt;beans:property name="userDetailsService" ref="userDetailsService"/&gt;
  &lt;/beans:bean&gt;
  
  
  
  &lt;beans:bean id="authenticationManager"
      class="org.springframework.security.authentication.ProviderManager"&gt;
      &lt;beans:property name="providers"&gt;
          &lt;beans:list&gt;
              &lt;beans:ref local="authenticationProvider" /&gt;
          &lt;/beans:list&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  &lt;authentication-manager&gt;
      &lt;authentication-provider user-service-ref="userDetailsService"&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;    
  </code></pre>
  
  <p></p>
  
  <p>servlet-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      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"&gt;
  
  
  &lt;annotation-driven /&gt;
  
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
  &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
  &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  
                                                &lt;!-- Data source configuration --&gt;
  
  &lt;!-- JDBC configuration for ORM --&gt;
  &lt;beans:bean id="dbDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
     &lt;beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
     &lt;beans:property name="url" value="jdbc:mysql://localhost:3306/dbName"/&gt;
     &lt;beans:property name="username" value="root"/&gt;
     &lt;beans:property name="password" value=""/&gt;
  &lt;/beans:bean&gt;   
  
  &lt;!-- Hibernate session Factory --&gt;
  &lt;beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
     &lt;beans:property name="dataSource" ref="dbDataSource" /&gt;
  
     &lt;!-- All the model packages with hibernate annotations that need to be scanned. --&gt;
     &lt;beans:property name="packagesToScan"&gt;
         &lt;beans:value&gt;
             com.package.registration.models
         &lt;/beans:value&gt;
     &lt;/beans:property&gt;
  
     &lt;!-- Hibernate specific properties --&gt;
     &lt;beans:property name="hibernateProperties"&gt;
         &lt;beans:props&gt;
             &lt;beans:prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/beans:prop&gt;
             &lt;beans:prop key="hibernate.show_sql"&gt;true&lt;/beans:prop&gt;
             &lt;beans:prop key="hibernate.format_sql"&gt;true&lt;/beans:prop&gt;
             &lt;beans:prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/beans:prop&gt;
             &lt;beans:prop key="org.hibernate.transaction"&gt;true&lt;/beans:prop&gt;
         &lt;/beans:props&gt;
     &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  &lt;!-- A transaction manager for working with Hibernate SessionFactories --&gt;
  &lt;beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;beans:property name="sessionFactory" ref="sessionFactory"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;context:component-scan base-package="com.package.app" /&gt;   
  </code></pre>
  
  <p></p>