I want to gradually transition Spring XML configurations into Java configurations. Will there be any issues having the same beans definitions in both the XML and Java @Configuration?
When a duplicate bean is detected (by bean id) during the bean definition phase, it replaces the definition of the previous bean. If you have identical bean definitions (XML and java config), then it should have no impact to you. As you are moving to Java Config, it would be important to load any duplicate XML beans first, so that you are confident that the Java Config bean is the last one loading, and the one used to build the bean. If the XML bean was loading second, you could not be sure that the Java Config bean was set up correctly (as it was replaced by XML).
EDIT: I created a project which was based on XML, and then added @Configuration based beans. My observation was that Spring has no problem with duplicate bean definitions (by id), however in the short time I tried, the XML bean definition overrode the java config @Bean. It is up to you if you want to attempt to get @Configuration beans to override XML Beans.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With