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.
相关问题
- slurm: use a control node also for computing
- java.lang.IllegalArgumentException: Cannot set to
- Spring Data MongoDB - lazy access to some fields
- Declaring an explict object dependency in Spring
- Decoding body parameters with Spring
相关文章
- java JDK动态代理和cglib动态代理最后获取的代理对象都为null的问题
- org.xml.sax.SAXParseException; lineNumber: 7; colu
- SpringMVC如何把File封装到Map中?
- Spring: controller inheritance using @Controller a
- How to load @Configuration classes from separate J
- Java spring framework - how to set content type?
- Java/Spring MVC: provide request context to child
- Spring 5 Web Reactive - Hot Publishing - How to us
i did not know that spring can mix configurations. here is the detailed and very useful example.
Bean1 is the actual bean we're configuring.
Fire is dependency interface
and dummy implementation 1
and dummy implementation 2
config.xml
and main class
here is the output
Although annotation resolves dependency to FireImpl1, xml config overrided with FireImpl2. very nice.
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.
For example, if you have
In this case, the XML definition of
beanA
should take precedence.