簡體   English   中英

如何在xml中按條件創建bean?

[英]How to create beans by condition in xml?

我正在使用xml config創建以下bean:

<int-ip:tcp-outbound-gateway id="gate"
    request-channel="input"
    reply-channel="clientBytes2StringChannel"
    connection-factory="factory"/>

如何根據條件(例如,application.properties中包含的值)配置它?

我春季4我可以使用@ConditionalOnExpression("SpEL") ,但是如何在xml中實現相同的目的呢?

您可以使用Spring Profiles有條件地創建bean。 例如

<beans profile="dev">
    <bean id="devDatasourceConfig" class="" />
</beans>

<beans profile="production">
    <bean id="productionDatasourceConfig" class=" " />
</beans>

您可以按以下方式激活配置文件:

JVM系統參數:

-Dspring.profiles.active=dev

要么

環境變量:

export spring_profiles_active=dev

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM