Spring Integration-服务参与者为文件写入操作抛出错误



我目前正在编写一个示例测试程序,以获取文件并简单地移动到另一个目录(我将添加代码来处理文件内容(。我使用的是:Spring Boot(2.1.9.RELEASE(和Spring Integration(5.1.8.RELEASE

我有一个错误代码。(查看帖子底部的错误详细信息(

渐变文件:

implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.integration:spring-integration-file'
@EnableIntegration
@IntegrationComponentScan
@SpringBootApplication
public class IntegrationApplication {
public static void main(String[] args) {
SpringApplication.run(CpKiboIntegrationApplication.class, args);
}
@Bean
public FileWritingMessageHandler fileWritingMessageHandler() {
return new FileWritingMessageHandler(new File("outDir"));
}
@Bean
@InboundChannelAdapter(channel = "fileInputChannel", poller = @Poller(fixedDelay = "5000"))
public MessageSource<File> pollableFileSource() {
FileReadingMessageSource fileReadingMessageSource = new FileReadingMessageSource();
fileReadingMessageSource.setDirectory(new File("inputDir"));
fileReadingMessageSource.setFilter(new SimplePatternFileListFilter("*.txt"));
return fileReadingMessageSource;
}
}
@Service
public class ActivatorService {
@Autowired
private FileWritingMessageHandler fileWritingMessageHandler;
@ServiceActivator(inputChannel = "fileInputChannel")
public MessageHandler fileReceiver(Message<?> message) {
fileWritingMessageHandler.setFileExistsMode(FileExistsMode.REPLACE);
fileWritingMessageHandler.setDeleteSourceFiles(true);
fileWritingMessageHandler.setExpectReply(false);
fileWritingMessageHandler.setAutoCreateDirectory(true);
return fileWritingMessageHandler;
}
}

启动时没有错误,但一旦我把文件放在"inputDir"文件夹中,我就会收到以下警告,然后出错:(注意:它确实执行了预期的操作,文件从源文件中删除,新文件在outDir文件夹中创建。(

o.s.i.expression.ExpressionUtils:创建没有beanFactory 的EvaluationContext

错误:

位于org.springframework.integration.exexpression.ExpressionUtils.createStandardEvaluationContext(ExpressionUtils.java:86(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]位于org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext(AbstractExpressionEvaluator.java:116(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]位于org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext(AbstractExpressionEvaluator.java:102(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]网址:org.springframework.integration.util.AbstractExpressionEvaluator.evalateExpression(AbstractExpressionEvaluator.java:172(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]网址:org.springframework.integration.util.AbstractExpressionEvaluator.evalateExpression(AbstractExpressionEvaluator.java:160(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]位于org.springframework.integration.file.DefaultFileNameGenerator.generateFileName(DefaultFileNameGenerator.java:70(~[spring-integration-file-5..1.8.RELEASE.jar:5.1.8.RELEASE]位于org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessage Handler.java:494(~[spring-integration-file-5..1.8.RELEASE.jar:5.1.8.RELEASE]位于org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyPProducingMessageHandler.java:123(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]位于org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:176(~[spring-integration-core-5..1.8.RELEASE.jar:5.1.8.RELEASE]网址:com.ignitiv.cpkibointegration.ActivatorService.fileReceiver(ActivatorService.java:36(~[classes/:na]位于java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method(~[na:na]位于java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62(~[na:na]位于java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43(~[na:na]位于java.base/java.lang.reflect.Method.ioke(Method.java:566(~[na:na]

原因:

由:org.springframework.messaging.core.DestinationResolutionException引起:没有可用的输出通道或replyChannel标头位于org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducengHandler.java:426(位于org.springframework.integration.handler.AbstractMessageProducingHandler.doProduceOutput(AbstractMessageProduceHandler.java:284(位于org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProduceHandler.java:265(位于org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducengHandler.java:223(位于org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyPProducingMessageHandler.java:129(位于org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:169(…还有26个

FileWritingMessageHandler必须是@Bean

您自己调用new,所以它不由Spring管理。

在任何情况下,您都不希望为每条消息都有一个新的处理程序。

@Bean
@ServiceActivator(inputChannel = "fileInputChannel")
public MessageHandler fileReceiver() {
FileWritingMessageHandler handler = new FileWritingMessageHandler(new File("outDir"));
handler.setFileExistsMode(FileExistsMode.REPLACE);
handler.setDeleteSourceFiles(true);
handler.setExpectReply(false);
handler.setAutoCreateDirectory(true);
return handler;
}

最新更新