[英]Spring context:property-placeholder for a boolean value
I am working on an application where I have two classes both implementing a common interface. 我正在开发一个应用程序,其中有两个都实现一个公共接口的类。 So in time of bean declaration, I am going to mark one of them primary in my app-context.xml file.
因此,在进行bean声明时,我将在我的app-context.xml文件中将其中一个标记为主要。 I can achieve this by simply declaring the primary bean like this:
我可以这样简单地声明主bean来实现:
<bean id="oracleImpl" class="com.me.dao.OracleImpl" primary="true">
</bean>
Now I don't want to hard code which of the beans is going to be the primary bean, rather want to read the true/false value from a properties file. 现在,我不想硬编码哪个bean将成为主bean,而是想从属性文件中读取true / false值。 So I went like this:
所以我就这样:
<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>
The values of oracle.primary and pgsql.primary are defined in the file jdbc.properties along with other jdbc (non-boolean) properties. oracle.primary和pgsql.primary的值与其他jdbc(非布尔型)属性一起在文件jdbc.properties中定义。
But it doesn't work and says, "'${oracle.primary}' is not a valid value for 'boolean'" 但是它不起作用,并说:“'$ {oracle.primary}'不是'boolean'的有效值”
I have a feeling it is something to do with the xsd validators. 我觉得这与xsd验证程序有关。 Browsing through this site and google gave me this much idea, but got no real solution.
浏览该网站和谷歌给了我很多想法,但没有真正的解决方案。 Can any body help?
有身体可以帮助吗?
This will not work. 这是行不通的。
As of 3.2.5.RELEASE only the following bean definition elemets support property placeholder: 从3.2.5.RELEASE开始,仅以下Bean定义要素支持属性占位符:
See the BeanDefinitionVisitor 's visitBeanDefinition
method for the details. 有关详细信息,请参见BeanDefinitionVisitor的
visitBeanDefinition
方法。 This method is used by the PlaceholderConfigurerSupport . PlaceholderConfigurerSupport使用此方法。
I would recommend you to create a feature request in the spring issue management system . 我建议您在Spring Issue Management系统中创建功能请求。
PS: if you create an issue please add a comment to the issues url. PS:如果您创建问题,请在问题网址中添加评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.