我正在尝试构建一个带有spring集成的spring启动项目,以使用自定义入站通道适配器处理传入的as2消息。由于某种原因,适配器的ref参数没有为我的类找到bean定义。
我有以下春季参考文件和在线资源,并有以下理解:
- 添加指向我的spring集成xml文件的
@ImportResource("/integration/integration.xml")
注释会将其添加到应用程序上下文中
@SpringBootApplication
@ImportResource("/integration/integration.xml")
public class MyApplication implements ServletContextListener {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
- 在我的类上添加
@Component
注释应该可以使它作为bean被我的spring引导应用程序自动检测
@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 !!! ------");
}
}
- ,但在
integration.xml
文件中运行应用程序时出现错误,并显示以下消息:
A component required a bean named 'com.example.MyHandlerModule' that could not be found.
作为参考,这里是我的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"
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>
我有什么东西不见了吗?
错误是正确的:在没有任何自定义名称的情况下,框架使其类似于myHandlerModule
——基于简单类名的驼色情况。该包不涉及bean命名。不确定是什么让你在引用中指向完全限定的类名…