简体   繁体   English

Spring在xml配置文件中重复bean定义在!stage中一个在开发人员中

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

My application has 3 possible profiles - dev, stage and prod. 我的应用程序有3种可能的配置文件-开发人员,阶段和产品。 My spring boot application has a xml config with 2 profiles that seem to be not working. 我的Spring Boot应用程序有一个xml配置,其中包含2个配置文件,似乎无法正常工作。

<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". 在开发人员模式下,我的应用程序不会以某种方式选择开发人员定义,而是默认使用profile =“!stage”中定义的bean定义。

As mentioned I need the profile="!stage" to hold common beans in dev and prod. 如前所述,我需要profile =“!stage”在dev和prod中保存普通bean。

Specifying profile as dev matches both !stage and dev . 将profile指定为dev匹配!stagedev

you can define multiple profiles in bean declaration like this 您可以像这样在bean声明中定义多个配置文件

<beans profile="dev, prod">

You can defines bean declarations common to dev and prod here 您可以在此处定义dev和prod通用的bean声明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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