title: spring security bean not found exception
body: <p>I'm trying to set up spring security for an mvc project, and I'm having a hard time. I'm using the spring security 3.1.4.Release. I have a spring-security.xml file set up along with and mvc-dispatcher-servlet file set up for configuration. Right now I'm getting a bean not found exception for my User Details Bean. </p>
  
  <p>In intellij I get a "cannot resolve bean" message for the myUserDetailService. I also cannot resolve the package "controller". The root error when I run the project is:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'myUserDetailService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myUserDetailService' is defined
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
  </code></pre>
  
  <p>Here is my spring-security.xml file: </p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
           xmlns:beans="http://www.springframework.org/schema/beans"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
           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 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;!-- Enabling Spring beans auto-discovery --&gt;
     &lt;context:component-scan base-package="controller, com.company.admin" /&gt;
  
  &lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/admin/*" access="ROLE_USER"  /&gt;
      &lt;form-login login-page="/login" default-target-url="/admin/welcome"   authentication-failure-url="/loginfailed" /&gt;
      &lt;logout logout-success-url="/logout" /&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager&gt;
      &lt;authentication-provider user-service-ref="myUserDetailService"/&gt;
  &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Here is my mvc-dispatcher-servlet.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xsi:schemaLocation="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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
  
  &lt;!-- Enabling Spring beans auto-discovery --&gt;
  &lt;context:component-scan base-package="com.company.admin" /&gt;
  
  &lt;!-- Enabling Spring MVC configuration through annotations --&gt;
  &lt;mvc:annotation-driven /&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/pages/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Here is my web.xml:</p>
  
  <pre><code>&lt;web-app version="2.4"
  xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
  &lt;display-name&gt;Spring MVC Application&lt;/display-name&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;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          /WEB-INF/mvc-dispatcher-servlet.xml,
          /WEB-INF/spring-security.xml
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.ContextLoaderListener
      &lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I'm basically trying to follow this tutorial: <a href="http://kh-yiu.blogspot.com/2012/12/spring-mvc-security-custom.html" rel="nofollow">http://kh-yiu.blogspot.com/2012/12/spring-mvc-security-custom.html</a> and the UserDetailServiceImpl is pretty identical to that, but I do have it in a different folder in my main/java directory. It's important to note I use annotations to declare the class:</p>
  
  <pre><code>@Service("myUserDetailService")
  public class UserDetailsServiceImpl implements UserDetailsService{
  </code></pre>
  
  <p>Any ideas? I'm having a very hard time finding tutorials with the same spring version that I'm using, so it's quite possible I've messed up xsd refs. Thanks.</p>