春天与基于XML的配置基于注解的框架覆盖配置? [英] Can spring framework override Annotation-based configuration with XML-based configuration?
本文介绍了春天与基于XML的配置基于注解的框架覆盖配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能否Spring框架为基础的注解覆盖配置与基于XML的配置?我需要改变它是通过注解已定义的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上下文允许您重新定义豆,用后来的定义压倒一切较早的。这应该适用于XML定义的豆类以及注释定义豆类,即便是混合。
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定义应该采取precedence。
In this case, the XML definition of beanA
should take precedence.
这篇关于春天与基于XML的配置基于注解的框架覆盖配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文