3

我正在使用 Spring 3.0.5.RELEASE 版本并具有以下配置:

<bean id="advice.audit" class="com.mysite.SuperClass" abstract="${myproperty.from.file}"/>

我越来越:

${myproperty.from.file}' is not a valid value for 'boolean'

我怎样才能实现这种行为,或者也许有人会提供更好的从属性控制 bean 创建的想法。

升级到 Spring 3.1 不是一种选择,因此无法使用 Spring Profiles。

4

1 回答 1

0

据我所知,该abstract属性并不意味着在运行时用属性值替换。abstract指示是否<bean>应将声明用作模板。例如,你可以有这个

<bean abstract="true">
    <property name="someField" value="some value" />
</bean>

如果 的值abstract在运行时以某种方式设置为false,Spring 将尝试为没有属性的<bean>声明创建一个 bean。class它会创造什么?

另请注意,在beansXSD 中,abstract属性的类型为xsd:boolean

<xsd:attribute name="abstract" type="xsd:boolean">
    <xsd:annotation>-<xsd:documentation>
        <![CDATA[ Is this bean "abstract", that is, not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions? The default is "false". Specify "true" to tell the bean factory to not try to instantiate that particular bean in any case. Note: This attribute will not be inherited by child bean definitions. Hence, it needs to be specified per abstract bean definition. ]]>
    </xsd:documentation>
</xsd:annotation></xsd:attribute>
于 2013-10-29T12:34:44.007 回答