spring 框架可以用基于 XML 的配置覆盖基于 Annotation 的配置吗? [英] Can spring framework override Annotation-based configuration with XML-based configuration?
问题描述
spring框架可以用基于XML的配置覆盖基于Annotation的配置吗?我需要更改已经通过注释定义的 bean 的依赖关系,并且我不是 bean 的作者.
Can spring framework override Annotation-based configuration with XML-based configuration? I need to change a dependency of a bean which is already defined via annotations and i am not the author of the bean.
推荐答案
应该没问题.Spring bean 上下文允许您重新定义 bean,较晚的"定义覆盖较早的".这应该适用于 XML 定义的 bean 以及注释定义的 bean,即使它们是混合的.
This should be OK. A Spring bean context allows you to redefine beans, with "later" definitions overriding "earlier ones". This should apply to XML-defined beans as well as annotation-defined beans, even if they're mixed.
例如,如果你有
@Configuration
public class MyAnnotatedConfig {
@Bean
public Object beanA() {
...
}
}
<小时>
<bean class="com.xyz.MyAnnotatedConfig"/>
<bean id="beanA" class="com.xyz.BeanA"/>
在这种情况下,beanA
的 XML 定义应该优先.
In this case, the XML definition of beanA
should take precedence.
这篇关于spring 框架可以用基于 XML 的配置覆盖基于 Annotation 的配置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!