简体   繁体   English

Spring Boot 集成 - ref 无法识别适配器的 bean

[英]Spring boot integration - ref not recognizing bean for adapter

I am trying to build a spring boot project with spring integration to handle incoming as2 messages using a custom inbound-channel-adapter.我正在尝试使用 spring 集成构建一个 spring boot 项目,以使用自定义入站通道适配器处理传入的 as2 消息。 for some reason the ref argument of the adapter is not finding a bean definition for my class.由于某种原因,适配器的 ref 参数没有为我的类找到 bean 定义。

I have the followed spring reference files and online resources and have the following understanding:我有以下spring参考文件和网上资源,有以下理解:

  1. Adding the @ImportResource("\/integration\/integration.xml")<\/code> annotation pointing to my spring integration xml file adds it to the application context添加指向我的 spring 集成 xml 文件的@ImportResource("\/integration\/integration.xml")<\/code>注释将其添加到应用程序上下文<\/li><\/ol>
    @SpringBootApplication @ImportResource("\/integration\/integration.xml") public class MyApplication implements ServletContextListener { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); }<\/code><\/pre> 
              
    1. adding the @Component<\/code> annotation above my class should make it autodetectable as a bean by my spring boot application在我的类上方添加@Component<\/code>注释应该使它可以被我的 Spring Boot 应用程序自动检测为 bean<\/li><\/ol>
       @Component public class MyHandlerModule extends AbstractProcessorModule implements IProcessorStorageModule { private static final Logger LOGGER = LoggerFactory.getLogger(MyHandlerModule.class); @Override public boolean canHandle(@Nonnull String s, @Nonnull IMessage iMessage, @Nullable Map<String, Object> map) { LOGGER.info(" Handle Info:" + s); LOGGER.info(map.toString()); return s.equals(DO_STORE); } @SneakyThrows @Override public void handle(@Nonnull String s, @Nonnull IMessage iMessage, @Nullable Map<String, Object> map) { LOGGER.info("----- AS2 MESSAGE RECEIVED !!! ------"); } }<\/code><\/pre>
                            
                      
                      
      1. and yet I am getting an error when running the application in my integration.xml<\/code> file with the following message:但是在我的integration.xml<\/code>文件中运行应用程序时出现错误,并显示以下消息:<\/li><\/ol>
         A component required a bean named 'com.example.MyHandlerModule' that could not be found.<\/code><\/pre>

        For reference, here is my integration.xml<\/code> file:作为参考,这是我的integration.xml<\/code>文件:

         <?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" 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 http:\/\/www.springframework.org\/schema\/context https:\/\/www.springframework.org\/schema\/context\/spring-context.xsd"> <int:channel id="as2MessageChannel"\/> <int:inbound-channel-adapter id="as2" ref="com.example.MyHandlerModule" method="handle" channel="as2MessageChannel"\/> <\/beans><\/code><\/pre>

        Is there something I am missing?有什么我想念的吗?

        "

The error is correct : without any custom name the framework makes it like myHandlerModule<\/code> - the camel case based on BBC a simple class name .错误是正确的:没有任何自定义名称,框架使它像myHandlerModule<\/code> - 基于 BBC 的骆驼案例一个简单的类名。 The package is not involved in bean naming .该包不涉及 bean 命名。 Not sure what made you to point fully qualified class name in that ref…不确定是什么让您在该参考文献中指向完全限定的类名......

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM