Непонимание с JobLaunchRequest - PullRequest
0 голосов
/ 10 марта 2020

это мой предыдущий вопрос: Spring Integration + Spring Batch: работа не останавливается .

Проект работает хорошо с конфигурацией аннотации, но я хочу то же самое для xml config:)

xml конфигурация:

    <int:service-activator input-channel="fileInputChannel"
                           method="fileWritingMessageHandler"
                           output-channel="jobLaunchRequestChannel">
        <bean class="service.impl.IntegrationServiceImpl"/>
    </int:service-activator>

    <int:service-activator input-channel="jobLaunchRequestChannel"
                           method="jobLaunchRequest"
                           output-channel="jobLaunchingGatewayChannel">
        <bean class="service.impl.IntegrationServiceImpl"/>
    </int:service-activator>

    <batch-int:job-launching-gateway request-channel="jobLaunchingGatewayChannel"
                                     reply-channel="finish"/>

    <int:service-activator input-channel="finish"
                           ref="integrationServiceImpl"
                           method="finishJob">
    </int:service-activator>

IntegrationConfiguration. java :

    @Bean
    public FtpInboundFileSynchronizer ftpInboundFileSynchronizer() {
        FtpInboundFileSynchronizer fileSynchronizer = new FtpInboundFileSynchronizer(defaultFtpSessionFactory);
        fileSynchronizer.setRemoteDirectory(remoteDirectory);
        fileSynchronizer.setDeleteRemoteFiles(false);
        return fileSynchronizer;
    }

    @Bean
    @InboundChannelAdapter(channel = "fileInputChannel", poller = @Poller(cron = "*/5 * * * * ?"))
    public FtpInboundFileSynchronizingMessageSource ftpInboundFileSynchronizingMessageSource(FtpInboundFileSynchronizer fileSynchronizer) throws Exception {
        FtpInboundFileSynchronizingMessageSource messageSource = new FtpInboundFileSynchronizingMessageSource(fileSynchronizer);
        messageSource.setAutoCreateLocalDirectory(true);
        messageSource.setLocalDirectory(new File(localDirectory));
        messageSource.setLocalFilter(new AcceptOnceFileListFilter<>());
        return messageSource;
    }

IntegrationServiceImpl:

    @Override
    public FileWritingMessageHandler fileWritingMessageHandler() {
        FileWritingMessageHandler messageHandler = new FileWritingMessageHandler(new File(storageDirectory));
        messageHandler.setDeleteSourceFiles(true);
        messageHandler.setFileNameGenerator(message -> {
            Long timestamp = new Date().getTime();
            log.info(timestamp);
            return "test_" + timestamp;
        });
        return messageHandler;
    }

    @Override
    public JobLaunchRequest jobLaunchRequest(File file) throws IOException {
//    public JobLaunchRequest jobLaunchRequest(FileWritingMessageHandler fileWritingMessageHandler) throws IOException {
        String[] content = FileUtils.readFileToString(file, "UTF-8").split("\\s+");
        JobParameters jobParameters = new JobParametersBuilder()
                .addString("filename", file.getAbsolutePath())
                .addString("id", content[0])
                .addString("salary", content[1])
                .toJobParameters();
        log.info(jobParameters);
        return new JobLaunchRequest(increaseSalaryJob, jobParameters);
    }

    @Override
    public void finishJob() {
        log.info("Job finished");
    }

Как вы можете видеть эту конфигурацию xml, как и в предыдущей конфигурации пост-аннотации, НО у меня ошибка:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method jobLaunchRequest(org.springframework.integration.file.FileWritingMessageHandler) cannot be found on type service.impl.IntegrationServiceImpl 

Почему я не могу использовать jobLaunchRequest (Файл)? И если мне нужно использовать jobLaunchRequest (FileWritingMessageHandler), как я могу работать с файлом?

1 Ответ

0 голосов
/ 10 марта 2020

Метод jobLaunchRequest() определенно должен иметь аргумент File, потому что это действительно то, что создается как полезная нагрузка в ответном сообщении от FileWritingMessageHandler.

Ваше определение <int:service-activator input-channel="fileInputChannel" method="fileWritingMessageHandler"> неверно .

Поскольку вы хотели бы использовать FileWritingMessageHandler в качестве службы, вам следует рассмотреть возможность использования <int-file:outbound-gateway>.

service-activator предназначен для вызова методов POJO. Поскольку FileWritingMessageHandler является реализацией MessageHandler, ее необходимо использовать в <service-activator> непосредственно из атрибута ref без использования атрибута method.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...