title: spring application-security configuration bean scan
body: <p>In my project, I needed a custom userDetailsService, So I declaire it like this in certain package: </p>
  
  <pre><code>@Service
  @Ihm(name = "userDetailsService")// ignore Ihm, it's just a custom annotation, which works fine
  public class UserDetailsServiceImpl implements UserDetailsService 
  </code></pre>
  
  <p>And in my application-security.xml file, I added component-scan, </p>
  
  <pre><code>&lt;context:component-scan base-package="path(including the userDetailsService for sure)" /&gt;
  
  &lt;context:annotation-config /&gt;
  </code></pre>
  
  <p>which didn't help me find my annotated bean, I got bean no defined exception.</p>
  
  <p>The only way worked in my case is :
  1.remove the service annotation
  2.create the bean in the application-security.xml with beans:bean,id,class.
  this works fine.</p>
  
  <p>What's more funny is this, when I kept both the component-scan, and the annotation, I got an ID duplicated(more than one bean, ask to specify the ID) error.</p>
  
  <pre><code> More than one UserDetailsService registered. Please use a specific Id reference in &lt;remember-me/&gt; &lt;openid-login/&gt; or &lt;x509 /&gt; elements.
  </code></pre>
  
  <p>So this means the <code>@Service</code> did create the bean, but y won't the security.xml find it?</p>