从xml到Java的Spring Integration Bean。现在我为每个@InboundChannelAdapter获取新的控制台日志,这是我之前没有得到的:
AbstractPollingEndpoint task-scheduler-7 DEBUG在轮询期间没有收到消息,返回'false'
这是初始配置:
<file:inbound-channel-adapter id="the-file-input"
directory="file:${import.file.dir.incomingFileDir}" channel="the-input" filter="customFilter" />
<si:channel id="the-input" />
<si:service-activator input-channel="the-input"
output-channel="job-requests" ref="theJobLauncher" />
<bean id="theJobLauncher" class="com.example.POJO">
</bean>
新的Java配置:
@Bean(name="theInput")
public MessageChannel manifestInputChannel() {
return new DirectChannel();
}
@Bean(name="theFileInput")
@InboundChannelAdapter(channel="theInput")
public MessageSource<File> filesInboundChannelAdapter(@Value("${import.file.dir.incomingFileDir}") String incomingDirectory){
FileReadingMessageSource sourceReader = new FileReadingMessageSource();
sourceReader.setDirectory(new File(incomingDirectory));
sourceReader.setFilter(customFileFilter);
sourceReader.afterPropertiesSet();
return sourceReader;
}
@Bean
@ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel")
public Pojo theJobLauncher() {
Pojo theJobLauncher = new Pojo();
return theJobLauncher;
}
theJobJaucher使用@MessageEndpoint注释和@ServiceActivator方法引用一个类
这个新的控制台日志行是否正常或我的配置有问题?
你所指的恰好是在AbstractPollingEndpoint
:
if (message == null) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Received no Message during the poll, returning 'false'");
}
result = false;
}
所以,这绝对意味着你已经以某种方式将org.springframework.integration
类别的记录器配置为DEBUG
级别。
尽管如此,这并没有伤害。您只是在以前的版本中没有该日志记录配置。
你不需要自己打电话给sourceReader.afterPropertiesSet();
。这是一个应用程序上下文回调,它确实会被调用,因为你将它声明为bean。
你的@ServiceActivator
定义不正确。只有在使用@Bean
实现时,才能存在MessageHandler
注释。
您可以将@ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel")
移动到Pojo
方法,并使用@Bean
为该Pojo
声明一个bean。或者既然你已经在该类上使用了@MessageEndpoint
,你可以考虑启用@ComponentScan
让应用程序上下文为你的类提取一个bean。
另一种方式真的像MessageHandler
实现调用你的Pojo
:
@Bean
@ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel")
public MessageHandler theJobLauncherServiceActivator(Pojo theJobLauncher) {
return new MethodInvokingMessageHandler(theJobLauncher, (String) null);
}