I have an existing bean overrideBean defined in spring.xml that I would like to override with annotations. I tried the following override bean:
@Configuration @ImportResource({"/spring.xml"}) public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DdwMain.class); Object o = context.getBean("overrideBean");
Using the code above, the bean from the spring.xml configuration spring.xml always created and returned by calling context.getBean .
The bean can be overridden by including another XML configuration file in @ImportResource , however I would prefer to find a solution using annotations would be cleaner.
source share