如果我在 Spring 2.5 中使用组件扫描,但又在 xml 中定义了一个 Controller 。
我是否在我的应用程序上下文中得到了这个 bean 的两个实例?如果是这样,将为其相关的 RequestMappings 调用哪个实例?
<bean id="myController" class="domain.MyController">
<property name="filters">
<list>
<ref local="filter1"/>
<ref local="filter2"/>
</list>
</property>
</bean>
最佳答案
如果您向 Spring 请求给定接口(interface)的一个 bean,并且您有该接口(interface)的两个 bean,那么您会从 Spring 容器中得到一个异常。
此规则的一个异常(exception)是,如果您的组件标有 @Primary
或 XML bean 的 primary 属性设置为 true。
关于java - 我可以覆盖通过组件扫描实例化的 spring bean 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2874355/