Java 在Spring集成中,如何在路由器通道中使用Util常量
我有一个用例,我在一个类中定义了所有常量Java 在Spring集成中,如何在路由器通道中使用Util常量,java,spring,spring-integration,Java,Spring,Spring Integration,我有一个用例,我在一个类中定义了所有常量 public class MyExampleConstants { public static String FOO1 = "hulcSmash"; public static String FOO2 = "billionairePlayBoy"; public static String FOO3 = "capShield"; } 现在,我在routerChan中使用类似的方法来映射值: //using exact strin
public class MyExampleConstants {
public static String FOO1 = "hulcSmash";
public static String FOO2 = "billionairePlayBoy";
public static String FOO3 = "capShield";
}
现在,我在routerChan中使用类似的方法来映射值:
//using exact string match in mapping value, however, want to see if the constants be used here.
<int:router input-channel="powRouterChan" resolution-required="false" expression="payload.avengersVO.powType" default-output-channel="flowEndPoint">
<int:mapping value="hulcSmash" channel="avengersHulcChan" />
<int:mapping value="billionairePlayBoy" channel="avengersIRManChan" />
<int:mapping value="capShield" channel="avengersCapAmericaChan" />
</int:router>
<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"/>
<int:router input-channel="powRouterChan" resolution-required="false" expression="payload.avengersVO.powType" default-output-channel="flowEndPoint">
<int:mapping value="foo1" channel="avengersHulcChan" />
<int:mapping value="foo2" channel="avengersIRManChan" />
<int:mapping value="foo3" channel="avengersCapAmericaChan" />
</int:router>
//但是,在映射值中使用精确字符串匹配,希望查看此处是否使用常量。
在路由器表达中,类似于:
//Now these placeholders are being configured in properties
<int:router input-channel="channelABC" expression=" !payload.avengersVO.powType.equals('${avengers.hulc.smash}')
and !payload.avengersVO.powType.equals('${avengers.billionaire.PlayBoy}')
and !payload.avengersVO.powType.equals('${avengers.capShield}') ? 'flowEndpoint' : 'civilWarsChan'"/>
//现在正在属性中配置这些占位符
现在,我已将常量添加到上下文中,并希望在路由器通道中将它们用作映射值:
//using exact string match in mapping value, however, want to see if the constants be used here.
<int:router input-channel="powRouterChan" resolution-required="false" expression="payload.avengersVO.powType" default-output-channel="flowEndPoint">
<int:mapping value="hulcSmash" channel="avengersHulcChan" />
<int:mapping value="billionairePlayBoy" channel="avengersIRManChan" />
<int:mapping value="capShield" channel="avengersCapAmericaChan" />
</int:router>
<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"/>
<int:router input-channel="powRouterChan" resolution-required="false" expression="payload.avengersVO.powType" default-output-channel="flowEndPoint">
<int:mapping value="foo1" channel="avengersHulcChan" />
<int:mapping value="foo2" channel="avengersIRManChan" />
<int:mapping value="foo3" channel="avengersCapAmericaChan" />
</int:router>
要使用我在上面声明的常量将上面的表达式更新为类似的内容:
<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'"/>
请告诉我怎么用这个。提前感谢。您可以使用
T
操作员在原始映射路由器中直接执行此操作:
<int:router input-channel="powRouterChan" resolution-required="false" expression="payload.avengersVO.powType" default-output-channel="flowEndPoint">
<int:mapping value="#{T(com.marvel.avengers.hulc.util.MyExampleConstants).FOO1}" channel="avengersHulcChan" />
...
</int:router>
...
或使用静态:
<int:router input-channel="powRouterChan" resolution-required="false" expression="payload.avengersVO.powType" default-output-channel="flowEndPoint">
<int:mapping value="#{foo1}" channel="avengersHulcChan" />
...
</int:router>
...
如果出于某种原因必须在表达式中执行此操作,请使用@foo1
,其中@
表示对bean的引用。但前两种解决方案更有效