简体   繁体   中英

Spring duplicated bean definition in xml profiles one in !stage and another in dev

My application has 3 possible profiles - dev, stage and prod. My spring boot application has a xml config with 2 profiles that seem to be not working.

<bean id="globalBean">
    <ref bean="myBean">
</bean>

<beans profile="!stage">
    <bean id="myBean">
        <property name="name" value="notStage" />
    </bean>
    <!--There are more bean definitions here common for dev and prod and have reference to myBean defined above-->
</beans>

<beans profile="dev">
    <bean id="myBean">
        <property name="name" value="dev" />
    </bean>
</beans>

<beans profile="stage">
    <bean id="myBean">
        <property name="name" value="stage" />
    </bean>
</beans>

In dev mode, my application doesn't somehow pick the dev definition and defaults to the bean definition defined in profile="!stage".

As mentioned I need the profile="!stage" to hold common beans in dev and prod.

Specifying profile as dev matches both !stage and dev .

you can define multiple profiles in bean declaration like this

<beans profile="dev, prod">

You can defines bean declarations common to dev and prod here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM