event:带有payload-expression的inbound-channel-adapter,无法解析bean

时间:2014-07-28 21:16:33

标签: events spring-integration

我正在尝试使用事件:inbound-channel-adapter作为ApplicationEventListener来捕获ContextRefreshedEvent,这样我就可以动态启动一个文件:inbound-channel-adapter,如:

<file:inbound-channel-adapter id="filesIn" auto-startup="false"
    directory="${input.location}" channel="fileInChannel">
    <integration:poller ref="filesInPoller" />
</file:inbound-channel-adapter>


<event:inbound-channel-adapter id='appStarter' channel="nullChannel"                                    
                  error-channel="errorChannel" 
                  event-types="org.springframework.context.event.ContextRefreshedEvent"
                  payload-expression="@filesIn.start()"/>

但是我得到以下错误,表明sPel payload-expression找不到filesIn bean:

Exception in thread "main" org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'filesIn'
at org.springframework.expression.spel.ast.BeanReference.getValueInternal(BeanReference.java:45)
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:49)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:72)
at org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer.sendEventAsMessage(ApplicationEventListeningMessageProducer.java:113)
at org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer.onApplicationEvent(ApplicationEventListeningMessageProducer.java:91)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:96)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:948)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

我是否相信file:inbound-channel-adapter能够以这种方式启动?

由于

1 个答案:

答案 0 :(得分:0)

您使用的是什么版本的Spring Integration?引用bean @filesIn的能力已添加到3.0中的此适配器。

如果您使用2.2或更低版本,请升级到当前版本(或至少3.0.4)。

在任何情况下,您都不能将该命令发送到nullChannel,它会评估为null而您无法拥有null个有效负载;您必须将'@filesIn.start()'发送给<control-bus/>

编辑:

或者,&#34; @filesIn.start() == null ? 'foo' : 'bar'&#34;会将foo发送到nullChannel