首页 文章

使用Spring Integration将文件复制到另一个引发异常的目录的基本示例

提问于
浏览
1

我是Spring Integration的初学者 . 我写了这个代码,它是在spring boot中引发异常“Bean named'messageSource'应该是'org.springframework.context.MessageSource'类型,但实际上是'org.springframework.integration.file.FileReadingMessageSource类型“”

码:

@Configuration
/*@EnableIntegration annotation designates this class as a Spring Integration configuration.*/
@EnableIntegration
public class SIConfig {

    @Bean
    public MessageChannel channel() {
        return new DirectChannel();
    }
    //bydefault name of method
    @Bean
    public MessageSource messageSource() {
        FileReadingMessageSource ms= new FileReadingMessageSource();
        ms.setDirectory(new File("C:\\Users\\payal\\Pictures"));
        ms.setFilter(new SimplePatternFileListFilter("*.mp4"));
        return ms;
    }

    @Bean
    public MessageHandler handler() {
        FileWritingMessageHandler handler= new FileWritingMessageHandler(new File("C:\\Users\\payal\\Documents\\batch7"));
        handler.setFileExistsMode(FileExistsMode.IGNORE);
        handler.setExpectReply(false);
        return handler;

    }

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from(messageSource(),  configurer -> configurer.poller(Pollers.fixedDelay(10000)))
                .channel(channel())
                .handle(handler()).get();
    }

}

自使用启动以来,版本会自动管理

上传代码n GitHub:

https://github.com/LearningNewTechnology/SpringIntegrationOne

任何帮助将非常感激 .

1 回答

  • 1

    将bean的名称更改为,例如

    @Bean
    public MessageSource myMessageSource() {
    

    Spring框架(context)有另一种类型的 MessageSource 和Spring Boot自动配置创建一个名为 messageSource 的bean,因此你的bean与之相撞 .

相关问题