Spring integration 对JobLaunchRequest的误解

Spring integration 对JobLaunchRequest的误解,spring-integration,spring-batch,Spring Integration,Spring Batch,这是我之前的问题: Project可以很好地使用注释配置,但我希望在xml配置中使用相同的配置: xml配置: <int:service-activator input-channel="fileInputChannel" method="fileWritingMessageHandler" output-channel="jobLaunchRequestChannel"&g

这是我之前的问题:

Project可以很好地使用注释配置,但我希望在xml配置中使用相同的配置:

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>
正如您可以看到的,此xml配置与之前的post annotation配置类似,但我有一个错误:

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 
为什么我不能使用jobLaunchRequestFile?如果我需要使用jobLaunchRequestFileWritingMessageHandler,我如何操作file?

jobLaunchRequest方法肯定必须带有一个file参数,因为这确实是FileWritingMessageHandler在回复消息中产生的有效负载

你的定义是错误的

由于您希望使用文件写入消息处理程序作为服务,您需要考虑使用Addio. 服务激活器用于调用POJO方法。由于FileWritingMessageHandler是MessageHandler实现,因此必须在中直接从ref属性使用它,而不使用任何方法属性

    @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");
    }
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