【问题标题】:Use spring integration command bus to start/stop AbstractEndpoints defined via Annotations使用 spring 集成命令总线来启动/停止通过 Annotations 定义的 AbstractEndpoints
【发布时间】:2017-04-27 16:32:05
【问题描述】:

我使用注解来定义 inboundChannelAdapter。 MyConfig.java

      @Bean
      @InboundChannelAdapter(value = "inputChannel", poller = @Poller(fixedRate = "5000"),
          autoStartup = "true")
      public MessageSource<File> input() {
        final FileReadingMessageSource result = new FileReadingMessageSource();
        result.setDirectory(new File("src/main/java/test"));
        return result;
      }

我尝试用 :

停止它
 MessageChannel controlChannel = ctx.getBean("controlBusChannel", MessageChannel.class);
      AbstractPollingEndpoint endpoint = ctx.getBean("myConfig.input.inboundChannelAdapter", AbstractPollingEndpoint.class);
      if(endpoint.isRunning()){
        controlChannel.send(new GenericMessage<String>("@"+endpoint.getComponentName()+".stop()"));
      }

但我得到了这个例外:

Exception in thread "main" org.springframework.messaging.MessageHandlingException: error occurred in message handler [ServiceActivator for [org.springframework.integration.handler.ExpressionCommandMessageProcessor@11b2519] (controlBus)]; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 10): Property or field 'input' cannot be found on object of type 'test.commandbus.MyConfig$$EnhancerBySpringCGLIB$$11f6b4ee' - maybe not public?
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:139)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at test.commandbus.Main.main(Main.java:32)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 10): Property or field 'input' cannot be found on object of type 'test.commandbus.MyConfig$$EnhancerBySpringCGLIB$$11f6b4ee' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:57)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:330)
    at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:150)
    at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:145)
    at org.springframework.integration.handler.ExpressionCommandMessageProcessor.processMessage(ExpressionCommandMessageProcessor.java:73)
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:89)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    ... 7 more

有没有办法停止适配器而不必为此定义特定的@Bean?

【问题讨论】:

  • 您拥有名为“input”的 spring bean,但 SPEL 正在寻找属性或字段“input”。
  • 尝试将您的 FileReadingMessagSource 公开为生命周期(而不是 MessageSource )以提供启动和停止方法

标签: java spring spring-integration spring-annotations


【解决方案1】:

你的解决方案是这样的:

"@'"+endpoint.getComponentName()+"'.stop()"

让它看起来像最后:

@'myConfig.input.inboundChannelAdapter'.stop()

否则我们有这个SpEL:

@myConfig.input.inboundChannelAdapter.stop()

因此,它评估 myConfig bean 并尝试访问其 input 属性。

【讨论】:

  • 非常感谢 Artem
猜你喜欢
  • 1970-01-01
  • 2021-12-22
  • 2022-12-01
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-02
相关资源
最近更新 更多