1

我有bean定义,例如

<bean id="DsdDetectorLogic" class="my class" init-method="init" lazy-init="true" >
    <property name="threshold" value="#{ properties.threshold }" />
    <property name="lag" value="#{ properties.lag }" />
    ...
</bean>

我需要在特定参数(滞后)上添加约束,如果此参数超过 3 的最大值或 1 的最小值,我需要它来获得默认值 1。此外,我需要收到一些警告消息,表明此参数收到了结果是默认值。

我熟悉使用 javax.validation.constraints.Min / Max 对代码中的字段进行注释的解决方案。

是否可以使用一些spring特性来编辑xml文件,或者唯一的解决方案是在调用setter时从java对象类中进行编辑?

4

1 回答 1

0

我将部分回答我的问题,因为我发现如何检查约束并通过 xml 发送默认值,警告消息仍然是一个难题。

我将使用 SPeL:

<bean id="DsdDetectorLogic" class="my class" init-method="init" lazy-init="true" >
    <property name="threshold" value="#{ properties.threshold }" />
    <property name="lag" value="#{ (1 > new Integer(properties.lag ) or 
                                    new Integer(properties.lag ) > 3) ? 1 : 
                                    properties.lag  }" />
    ...
</bean>
于 2013-01-24T11:02:32.727 回答