![](/img/trans.png)
[英]In Spring integration, how do I use Util constant in router channel
[英]How to use util constants in router expression?
我在我的上下文中定義了這些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"/>
我嘗試在路由器表達式中使用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'"/>
另一方面,我可以在表達式中使用它,但想看看我是否可以使用我在路由器表達式中定義的常量:
<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'"/>
有人可以幫助我知道,如何在路由器表達式中從這個bean獲取價值。 提前致謝。
這應該工作:
!payload.avengersVO.powType.equals(@foo2)
雖然,你的案例也很適合我:
<util:constant id="foo" static-field="org.springframework.integration.router.config.RouterParserTests.FOO"/>
<router input-channel="constantExpressionRouter" expression="'#{foo}'"/>
但是,請注意我將Bean Definition表達式包裝到文字引號中,以避免嘗試在運行時將其作為每個消息的屬性進行評估。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.