I'm working through Peter Mularien's Spring Security 3, and am having a problem setting up the UserDetailsManager.
I create the JdbcUserDetailsManager bean as follows:
<bean id="jdbcUserService" class="org.springframework.security.provisioning.JdbcUserDetailsManager">
<property name="dataSource" ref="mySqlDb" />
<property name="authenticationManager" ref="authenticationManager" />
</bean>
and autowire its UserDetailsManager interface in my controller like so:
@Autowired
public UserDetailsManager userDetailsManager;
When I start up the app to test it out, I get the following exception:
Error creating bean with name 'changePasswordController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.provisioning.UserDetailsManager com.ebisent.web.ChangePasswordController.userDetailsManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.security.provisioning.UserDetailsManager] is defined: expected single matching bean but found 2: [org.springframework.security.provisioning.JdbcUserDetailsManager#0, jdbcUserService]
I searched through my project to see if I might have set up (Jdbc)UserDetailsManager elsewhere, but I don't appear to have done so. If I remove the "id" attribute in the bean definition, then the ambiguity is between JdbcUserDetailsManager#0 and JdbcUserDetailsManager#1.
My web.xml references app-config.xml in two places:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring/app-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>