我的业务逻辑需要能够更改聚合器上配置的组超时。
代码如下:
@Autowired
AggregatingMessageHandler messageAggregator;
public void setTimeout(Integer timeoutValue) {
Expression timeoutExpression = new SpelExpressionParser().parseExpression(timeoutValue.toString());
messageAggregator.setGroupTimeoutExpression(timeoutExpression);
}
问题是:
- 我想向用户显示当前值,但是
- 吸气剂受到保护
可能的解决方案场景:
- 我应该在这个bean上注入一个表达式,然后更改它的值吗,
- 意思是,下次构建消息组时,它会用新的结果重新评估表达式吗
- 我应该用我自己的具有公共setter的处理程序来扩展AggregationMessageHandler吗
- 或者这是一个错误,应该在下一个版本中修复
不确定为什么将其称为bug,但您的需求不是标准的。
让我们试着一起想出一些解决方案!
由于您将在运行时更改group-timeout
,并且您确实不需要expression
,因为您的值仅为Integer
,因此可以使用org.springframework.integration.expression.ValueExpression
作为AtomicReference
bean的value
。
在这种情况下,您可以简单地显示current value to the user
:
@Autowired
private AtomicReference<ValueExpression> groupTimeoutExpression;
....
this.groupTimeoutExpression.get().getValue();
并将该AtomicReference
与新的ValueExpression
一起用作当前值,并将最后一个设置为AggregatingMessageHandler
。
在应用程序启动时,您应该对初始group-timeout
执行同样的操作。或者只需将value
复制/粘贴到<aggregator>
和AtomicReference
bean的group-timeout
属性中。
HTH