How to override an imported resource using Spring @Configuration?

Is it possible to override imported resources using Spring annotation configuration?

Configuration Class:

@Configuration
@ImportResource({"classpath:applicationContext.xml"})
public class CoreConfiguration {

    @Resource(name = "classA")
    private ClassA classA;

    @Bean(name = "nameIWantToOverride")
    private ClassB classB() {
       return new ClassB("different setting");
    }

}

ApplicationContext.xml includes:

<bean name="classA" class="a.b.c.ClassA">
     <property name="nameIWantToOverride" ref="classB" />
</bean>

If classA has a classB field, but I want it to use ClassB, which I define in my configuration class, is this possible? I tried to switch the order, but that did not help. XML seems to take precedence, because when I run a simple test to create an instance of the configuration, it never reaches the class method. If I change the name so that it does not match the bean in the XML file, then it reaches the classB method.

, -: Spring XML?, ?? , , .

, ?

: XML. , , .

+5
1

spring xml .

Spring XML

+5

All Articles