当试图从Spring Security的自动装配JdbcUserDetailsManager,我用下面的语句appcontext.xml(位于Web应用程序分开):春天的Autowire重复的问题
<bean class="org.springframework.security.provisioning.JdbcUserDetailsManager">
<property name="dataSource" ref="dataSource"/>
</bean>
当运行单元测试,一切都很好。当开始我的web应用程序,它有它自己的appcontext.xml包括原appcontext.xml,我得到一个错误重复:
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]
如何改进为了我的两个appcontext.xml两全,服务层测试和webapp分别运行?
感谢您的回答。我的问题不是webapp,而是与webapp无关的单元测试。没有bean定义,webapp运行良好,但是我不能在没有提到bean定义的情况下运行单元测试。 – 2010-08-01 17:26:51
没错。但是,您可以在@ContextConfiguration(locations = {myStringArrayOfXmlFiles})中传递尽可能多的xml文件。 换句话说,测试可以负责加载这两个XML文件,因此您不需要自己执行include操作。 – 2010-08-01 17:54:53
啊谢谢......不知道那个...... +1 – 2010-08-01 17:58:01