【问题标题】:Spring integration: no such method exception for custom inbound channel adapterSpring集成:自定义入站通道适配器没有此类方法异常
【发布时间】:2022-02-06 05:23:14
【问题描述】:

我正在尝试从我的As2MessageHandler 类调用processMessage 方法作为我使用自定义入站通道适配器进入spring 集成的入口点。但是我一直收到这个错误,说当它明显在类中时找不到方法:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'as2.source': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: no such method 'processMessage' is available on class com.as2example.myexample.handler.As2MessageHandler

as2MessageHandler 类:


@Component
public class As2MessageHandler extends AbstractProcessorModule implements IProcessorStorageModule {

    private static final Logger LOGGER = LoggerFactory.getLogger(As2MessageHandler.class);


    @Override
    public boolean canHandle(@Nonnull String s, @Nonnull IMessage iMessage, @Nullable Map<String, Object> map) {
        LOGGER.info(" Handle Info:" + s);

        return s.equals(DO_STORE);
    }

    @Override
    public void handle(@Nonnull String s, @Nonnull IMessage iMessage, @Nullable Map<String, Object> map) throws AS2Exception {

        LOGGER.info("----- AS2 MESSAGE RECEIVED !!! ------");

        LOGGER.info(iMessage.getContentType());
        LOGGER.info(iMessage.getContentDisposition());
        LOGGER.info(iMessage.getAsString());

        processMessage(iMessage);

    }

    public String processMessage(IMessage message) {

        LOGGER.info("BEGIN PROCESSING MESSAGE");

        return message.getAsString();
    }


}

integration.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration
         https://www.springframework.org/schema/integration/spring-integration.xsd">



    <int:channel id="as2MessageChannel">
        <int:interceptors>
            <int:wire-tap channel="logger"/>
        </int:interceptors>
    </int:channel>

    <int:logging-channel-adapter id="logger" level="DEBUG"/>


    <int:inbound-channel-adapter id="as2" ref="as2MessageHandler" method="processMessage" channel="as2MessageChannel">

    </int:inbound-channel-adapter>



    <int:service-activator input-channel="as2MessageChannel" ref="orderServiceImpl" auto-startup="true"/>



</beans>

MyApplication 类:

@SpringBootApplication
@ImportResource("classpath:/integration/integration.xml")
public class MyApplication implements ServletContextListener {

    public static void main(String[] args) {


        SpringApplication.run(MyApplication.class, args);
    }


    @Override
    public void contextDestroyed (final ServletContextEvent sce)
    {
        ServletConfig.shutDown ();
        AS2WebAppListener.staticDestroy ();
    }

}

谁能提供有关为什么 spring 集成无法识别 As2MessageHandler 类中的 processMethod 的见解?我尝试将方法更改为使用 messagebuilder 并返回 Message 类型,但这不是问题。现在我想它必须是别的东西。

【问题讨论】:

    标签: java spring spring-boot spring-integration


    【解决方案1】:

    错误是正确的。由于方法的签名是错误的,而不是它的存在,它可能会产生一点误导。因此,由于入站通道适配器是流程的开始,因此该方法实际上不能有任何输入来为消息生成数据。因此,不清楚您对 IMessage 作为该方法的输入有何期望。

    不清楚您的设计是什么,但&lt;int:inbound-channel-adapter&gt; 中的 POJO 方法被轮询器调用为消息的数据源。换句话说,作为源的 POJO 方法不能有参数 - 只有返回。这就是引发该异常的原因。

    我在您的As2MessageHandler 中看不到任何可以作为入站通道适配器中消息源的内容。这个看起来更像是一个服务激活器。请修改您的设计以支持其他真正可用作该 AS2 协议中的数据源的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 2015-07-11
      • 2017-10-08
      • 2014-12-07
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 2014-05-31
      相关资源
      最近更新 更多