gpt4 book ai didi

java - Spring 上下文 :property-placeholder for a boolean value

转载 作者:行者123 更新时间:2023-11-30 08:27:01 25 4
gpt4 key购买 nike

我正在开发一个应用程序,其中有两个类都实现了一个公共(public)接口(interface)。因此,在声明 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(非 boolean )属性一起在文件 jdbc.properties 中定义。

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

我感觉这与 xsd validator 有关。浏览这个网站和谷歌给了我很多想法,但没有真正的解决方案。任何机构都可以提供帮助吗?

最佳答案

这行不通。

从 3.2.5.RELEASE 开始,只有以下 bean 定义元素支持属性占位符:

  • parent 姓名
  • bean类名
  • 工厂 bean 名称
  • 工厂方法名
  • 范围
  • 属性值
  • 索引构造函数参数
  • 通用构造函数参数

参见 BeanDefinitionVisitorvisitBeanDefinition 方法了解详细信息。 PlaceholderConfigurerSupport 使用此方法.

我建议您在 spring issue management system 中创建一个功能请求.

PS:如果您创建问题,请在问题 url 中添加评论。

关于java - Spring 上下文 :property-placeholder for a boolean value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21090484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com