title: Cannot resolve reference to bean while setting bean property 'userDetailsService'
body: <p>I'm doing my own custom security with Spring Security and a solr core, it seems like I did something wrong but I'm not sure what.</p>
  
  <p>Stack trace:</p>
  
  <pre class="lang-none prettyprint-override"><code>Caused by: java.lang.RuntimeException: 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 [5]; 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 'authenticationManager' while setting constructor argument; 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 while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'CustomUserDetails' is defined
      at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:231)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
  </code></pre>
  
  <p>This the <code>security-context.xml</code> file:</p>
  
  <pre class="lang-xml prettyprint-override"><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"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
          http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd"&gt;
  
      &lt;security:global-method-security
          secured-annotations="enabled"&gt;&lt;/security:global-method-security&gt;
      &lt;security:http auto-config="true" realm="Protected Web"
          pattern="/**" authentication-manager-ref="authenticationManager"&gt;
          &lt;security:csrf disabled="true" /&gt;
  
          &lt;security:intercept-url pattern="/index/**" access="hasAnyRole('ROLE_ADMIN','ROLE_USER')" /&gt;
  
          &lt;security:intercept-url pattern="/rest/api/1.0/**" access="isAuthenticated()" /&gt;
  
          &lt;security:intercept-url pattern="/**" access="permitAll" /&gt;
  
          &lt;security:form-login login-page="/login"
              username-parameter="j_username" login-processing-url="/j_spring_security_check"
              password-parameter="j_password" authentication-failure-url="/login?error=1"
              default-target-url="/index" always-use-default-target="true" /&gt;
  
          &lt;security:logout invalidate-session="true"
              delete-cookies="true" logout-url="/j_spring_security_logout"
              logout-success-url="/login" /&gt;
          &lt;security:session-management&gt;
              &lt;security:concurrency-control
                  max-sessions="2" /&gt;
          &lt;/security:session-management&gt;
      &lt;/security:http&gt;
  
  
  
         &lt;security:authentication-manager alias="authenticationManager"&gt;
          &lt;security:authentication-provider user-service-ref="CustomUserDetails" /&gt;
      &lt;/security:authentication-manager&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>The class <code>CustomUserDetails</code>: </p>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class CustomUserDetails implements UserDetailsService {
  
      private static final Logger logger = Logger.getLogger(StatusAppJob.class);
  
      @Autowired
      private UserAppRepository userAppRepository;
  
      @Override
      public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
  
          List&lt;UsuarioApp&gt; result =  getUserDetails(username);
  
          if(!result.isEmpty())
          {
  
          }
          else{
              throw new UsernameNotFoundException(username + " not found");
          }
  
          UserDetails user = new User(username, result.get(0).getPassword(), true, true, true, true, getAuthorities(result.get(0).getRol()));
               return user;
  
      }
  
      public Collection&lt;? extends GrantedAuthority&gt; getAuthorities(String rol) {
          List&lt;SimpleGrantedAuthority&gt; auths = new java.util.ArrayList&lt;SimpleGrantedAuthority&gt;();
          auths.add(new SimpleGrantedAuthority(rol));
          return auths;
      }
  
      public List&lt;UsuarioApp&gt; getUserDetails(String user) {
          // TODO Auto-generated method stub
  
          return userAppRepository.findUser(user);
      }
  
  }
  </code></pre>
  
  <p>The <code>app-context.xml</code> file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
          id="WebApp_ID" version="3.0"&gt;
          &lt;display-name&gt;secturv2&lt;/display-name&gt;
  
          &lt;context-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;
                  /WEB-INF/solr-config.xml,
                  /WEB-INF/Spring-Quartz.xml,
                  /WEB-INF/spring/security-context.xml,
                  /WEB-INF/spring/postgres-config.xml  
  
              &lt;/param-value&gt;
          &lt;/context-param&gt;
      &lt;!--,   /WEB-INF/spring/postgres-config.xml  --&gt;
          &lt;listener&gt;
              &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
          &lt;/listener&gt;
          &lt;listener&gt;
              &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
          &lt;/listener&gt;
  
          &lt;servlet&gt;
              &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
              &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
              &lt;init-param&gt;
                  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
                  &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
              &lt;/init-param&gt;
              &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;/servlet&gt;
  
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
              &lt;url-pattern&gt;/&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
  
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;jsp&lt;/servlet-name&gt;
              &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
  
          &lt;!-- Spring Security --&gt;
          &lt;filter&gt;
              &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
              &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
          &lt;/filter&gt;
  
          &lt;filter-mapping&gt;
              &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;/filter-mapping&gt;
  
      &lt;!--    Sesiones de Hibernate --&gt;
          &lt;filter&gt;
              &lt;filter-name&gt;OpenSessionInViewFilter&lt;/filter-name&gt;
              &lt;filter-class&gt;org.springframework.orm.hibernate4.support.OpenSessionInViewFilter&lt;/filter-class&gt;
              &lt;init-param&gt;
                  &lt;param-name&gt;sessionFactoryBeanName&lt;/param-name&gt;
                  &lt;param-value&gt;sfTurismo&lt;/param-value&gt;
              &lt;/init-param&gt;
          &lt;/filter&gt;
          &lt;filter-mapping&gt;
              &lt;filter-name&gt;OpenSessionInViewFilter&lt;/filter-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;/filter-mapping&gt;
  
          &lt;error-page&gt;
              &lt;error-code&gt;401&lt;/error-code&gt;
              &lt;location&gt;/error&lt;/location&gt;
          &lt;/error-page&gt;
  
          &lt;error-page&gt;
              &lt;error-code&gt;403&lt;/error-code&gt;
              &lt;location&gt;/error&lt;/location&gt;
          &lt;/error-page&gt;
  
          &lt;error-page&gt;
              &lt;error-code&gt;500&lt;/error-code&gt;
              &lt;location&gt;/error&lt;/location&gt;
          &lt;/error-page&gt;
  
      &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Added the <code>servlet-context.xml</code> file:</p>
  
  <pre class="lang-xml prettyprint-override"><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:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;annotation-driven /&gt;
      &lt;context:component-scan base-package="mx.sectur.turismo" /&gt;
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;resources location="/views/" mapping="/**" /&gt;
  
      &lt;beans:bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" /&gt;
  
      &lt;beans:bean
          class="org.springframework.data.repository.support.DomainClassConverter"&gt;
          &lt;beans:constructor-arg ref="conversionService" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;mvc:annotation-driven conversion-service="conversionService"&gt;
          &lt;mvc:argument-resolvers&gt;
              &lt;beans:bean
                  class="org.springframework.data.web.PageableHandlerMethodArgumentResolver"&gt;
                  &lt;beans:property name="maxPageSize" value="10"&gt;&lt;/beans:property&gt;
              &lt;/beans:bean&gt;
          &lt;/mvc:argument-resolvers&gt;
      &lt;/mvc:annotation-driven&gt;
  
      &lt;beans:bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;interceptors&gt;
          &lt;beans:bean id="webContentInterceptor"
              class="org.springframework.web.servlet.mvc.WebContentInterceptor"&gt;
              &lt;beans:property name="cacheSeconds" value="0" /&gt;
              &lt;beans:property name="useExpiresHeader" value="true" /&gt;
              &lt;beans:property name="useCacheControlHeader" value="true" /&gt;
              &lt;beans:property name="useCacheControlNoStore" value="true" /&gt;
          &lt;/beans:bean&gt;
      &lt;/interceptors&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Why I'm getting </p>
  
  <blockquote>
    <p>Cannot resolve reference to bean while setting bean property 'userDetailsService'"</p>
  </blockquote>
  
  <p>message?</p>