When trying to autowire JdbcUserDetailsManager from Spring Security, I use following statement in appcontext.xml (located separated from webapp):
<bean class="org.springframework.security.provisioning.JdbcUserDetailsManager">
<property name="dataSource" ref="dataSource"/>
</bean>
When running unit test all is fine. When starting my web app, which has it’s own appcontext.xml including the original appcontext.xml, I get an duplicate error:
No unique bean of type
[org.springframework.security.provisioning.JdbcUserDetailsManager] is defined:
expected single matching bean but found 2:
[org.springframework.security.provisioning.JdbcUserDetailsManager#0,
org.springframework.security.provisioning.JdbcUserDetailsManager#1]
How can I refine my two appcontext.xml in order to get both, the service layer tests and the webapp running respectively?
Why do you need to include the JdbcUserDetailsManager in your web/servlet application context? The WebApplicationContext gets the main ApplicationContext as a parent “automatically” (if you configure it correctly.) See this IBM article for an example of setting contextConfigLocation so the web app knows where to find the main ApplicationContext.
Or this example:
contextConfigLocation
/WEB-INF/main-application-config.xml