I'm currently writing a sample test program to get the file and simply move to another directory (I will be adding code to process the file contents). I'm using: Spring Boot (2.1.9.RELEASE) and Spring Integration (5.1.8.RELEASE)
I have code in place which is giving an error. (Look at the bottom of the post for the error details)
Gradle file:
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;
}
}
There is no error in startup, but as soon as I put the file in "inputDir" folder I get the below warnign and then error: (Note: it does perform the intended operation, file gets deleted from source and new file get created in outDir folder.)
o.s.i.expression.ExpressionUtils : Creating EvaluationContext with no beanFactory
Error:
at org.springframework.integration.expression.ExpressionUtils.createStandardEvaluationContext(ExpressionUtils.java:86) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext(AbstractExpressionEvaluator.java:116) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext(AbstractExpressionEvaluator.java:102) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:172) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:160) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.file.DefaultFileNameGenerator.generateFileName(DefaultFileNameGenerator.java:70) ~[spring-integration-file-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:494) ~[spring-integration-file-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:123) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:176) ~[spring-integration-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] at com.ignitiv.cpkibointegration.ActivatorService.fileReceiver(ActivatorService.java:36) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
Cause:
Caused by: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:426) at org.springframework.integration.handler.AbstractMessageProducingHandler.doProduceOutput(AbstractMessageProducingHandler.java:284) at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:265) at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:223) at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:129) at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:169) ... 26 more