简体   繁体   English

如何在路由器表达式中使用util常量?

[英]How to use util constants in router expression?

I've defined these util constants in my context. 我在我的上下文中定义了这些util常量。

<util:constant id="foo1" static-field="com.marvel.avengers.hulc.util.MyExampleConstants.FOO1"/>
<util:constant id="foo2" static-field="com.marvel.avengers.hulc.util.MyExampleConstants.FOO2"/>
<util:constant id="foo3" static-field="com.marvel.avengers.hulc.util.MyExampleConstants.FOO3"/>

I've tried using foo1 constant in my router expression, but it looks like #{foo1} is a bean id and not its value. 我尝试在路由器表达式中使用foo1常量,但看起来#{foo1}是一个bean id而不是它的值。

<int:router input-channel="channelABC" expression=" !payload.avengersVO.powType.equals(#{foo1}) 
        and !payload.avengersVO.powType.equals(#{foo2}) 
        and !payload.avengersVO.powType.equals(#{foo3}) ? 'flowEndpoint' : 'civilWarsChan'"/>

On the other hand I could use this in an expression but want to see if I could make use of the constants that I've defined in the router expression: 另一方面,我可以在表达式中使用它,但想看看我是否可以使用我在路由器表达式中定义的常量:

<int:router input-channel="channelABC" expression=" !payload.avengersVO.powType.equals(T(com.marvel.avengers.hulc.util.MyExampleConstants).FOO1) 
    and !payload.avengersVO.powType.equals(T(com.marvel.avengers.hulc.util.MyExampleConstants).FOO2) 
    and !payload.avengersVO.powType.equals(T(com.marvel.avengers.hulc.util.MyExampleConstants).FOO3) ? 'flowEndpoint' : 'civilWarsChan'"/>

Can someone help me to know, how to get value from this bean in router expression. 有人可以帮助我知道,如何在路由器表达式中从这个bean获取价值。 Thanks in advance. 提前致谢。

This should work: 这应该工作:

!payload.avengersVO.powType.equals(@foo2) 

Although, your case looks for me fine, too: 虽然,你的案例也很适合我:

<util:constant id="foo" static-field="org.springframework.integration.router.config.RouterParserTests.FOO"/>

<router input-channel="constantExpressionRouter" expression="'#{foo}'"/>

However, pay attention that I wrap the Bean Definition expression into the literal quotes to avoid an attempt to evaluate it as a property at runtime on each message. 但是,请注意我将Bean Definition表达式包装到文字引号中,以避免尝试在运行时将其作为每个消息的属性进行评估。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM