我正在开发一个应用程序,其中有两个类都实现了一个通用接口(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 名称
- 工厂方法名称
- 范围
- 属性值
- 索引构造函数参数
- 通用构造函数参数
请参阅BeanDefinitionVisitor的 visitBeanDefinition
方法了解详细信息。 PlaceholderConfigurerSupport 使用此方法.
我建议您在 spring issue management system 中创建功能请求.
PS:如果您创建问题,请在问题网址中添加评论。
关于java - Spring 上下文:property-placeholder for a boolean value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21090484/