Spring Integration - ошибка актера службы для операции записи файла - PullRequest
0 голосов
/ 08 ноября 2019

В настоящее время я пишу пример тестовой программы, чтобы получить файл и просто переместиться в другой каталог (я буду добавлять код для обработки содержимого файла). Я использую: Spring Boot (2.1.9.RELEASE) и Spring Integration (5.1.8.RELEASE)

У меня есть код, который выдает ошибку. (Подробности об ошибке смотрите в нижней части поста)

Файл Gradle:

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.)

osiexpression.ExpressionUtils: Создание EvaluationContext без beanFactory

Ошибка:

в org.springframework.integration.expression.ExpressionUtils.createStandardEvaluationContext (ExpressionUtils.java:86) ~ [spring-интеграции-core-5.1.8.RELEASE.jar: 5.1.8.RELEASE] в org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext (AbstractExpressionEvaluator.java:116) ~ [spring -gration-core-5.1.8.RELEASE. jar: 5.1.8.RELEASE] at org.springframework.integration.util.AbstractExpressionEvaluator.getEvaluationContext (AbstractExpressionEvaluator.java:102) ~ [spring -gration-core-5.1.8.RELEASE.jar: 5.1.8.RELEASE] в org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression (AbstractExpressionEvaluator.java:172) ~ [spring -gration-core-5.1.8.RELEASE. jar: 5.1.8.RELEASE] в org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression (AbstractExpressionEvaluator.java:160) ~ [spring -gration-core-5.1.8.RELEASE.jar: 5.1.8.RELEASE] вorg.springframework.integration.file.DefaultFileNameGenerator.generateFileName (DefaultFileNameGenerator.java:70) ~ [spring -gration-file-5.1.8.RELEASE.jar: 5.1.8.RELEASE] в org.springframework.integration.file.FileWritleressMage,~ [spring -gration-core-5.1.8.RELEASE.jar: 5.1.8.RELEASE] в org.springframework.integration.handler.AbstractMessageHandler.handleMessage (AbstractMessageHandler.java:176) ~ [spring -gration-core-5.1.8.RELEASE.jar: 5.1.8.RELEASE] в com.ignitiv.cpkibointegration.ActivatorService.fileReceiver (ActivavaService.ervice.erve.ervice.ervice.service.erv.jpg: 36) ~ [classes /: na] в java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод) ~ [na: na] в java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethoIhod.java: 62) ~ [na: na] в java.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) ~ [na: na] в java.base / java.lang.reflect.Method.invoke (Method.java:566) ~ [na: na]

Причина:

Причина: org.springframework.messaging.core.DestinationResolutionException: нет выводазаголовок -channel или replyChannel, доступный по адресу org.springframework.integration.handler.AbstractMessageProufactHandler.sendOutput (AbstractMessageProroductionHandler.java:426) по адресу org.springframework.integration.handler.AbstractMessageProducingHandler. .springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal (AbstractReplyProducingMessageHandler.java:129)в org.springframework.integration.handler.AbstractMessageHandler.handleMessage (AbstractMessageHandler.java:169) ... еще 26

1 Ответ

1 голос
/ 08 ноября 2019

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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...