簡體   English   中英

Spring上下文:布爾值的屬性占位符

[英]Spring context:property-placeholder for a boolean value

我正在開發一個應用程序,其中有兩個都實現一個公共接口的類。 因此,在進行bean聲明時,我將在我的app-context.xml文件中將其中一個標記為主要。 我可以這樣簡單地聲明主bean來實現:

<bean id="oracleImpl" class="com.me.dao.OracleImpl" primary="true">
</bean>

現在,我不想硬編碼哪個bean將成為主bean,而是想從屬性文件中讀取true / false值。 所以我就這樣:

<context:property-placeholder location="classpath:jdbc.properties"/>

<bean id="oracleImpl" class="com.me.dao.OracleImpl" primary="${oracle.primary}">
</bean>

<bean id="pgsqlImpl" class="com.me.dao.PgsqlImpl" primary="${pgsql.primary}">
</bean>

oracle.primary和pgsql.primary的值與其他jdbc(非布爾型)屬性一起在文件jdbc.properties中定義。

但是它不起作用,並說:“'$ {oracle.primary}'不是'boolean'的有效值”

我覺得這與xsd驗證程序有關。 瀏覽該網站和谷歌給了我很多想法,但沒有真正的解決方案。 有身體可以幫助嗎?

這是行不通的。

從3.2.5.RELEASE開始,僅以下Bean定義要素支持屬性占位符:

  • 父母名字
  • 豆類名稱
  • 工廠bean名稱
  • 工廠方法名稱
  • 范圍
  • 屬性值
  • 索引構造函數參數
  • 通用構造函數參數

有關詳細信息,請參見BeanDefinitionVisitorvisitBeanDefinition方法。 PlaceholderConfigurerSupport使用此方法。

我建議您在Spring Issue Management系統中創建功能請求。

PS:如果您創建問題,請在問題網址中添加評論。

暫無
暫無

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

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