如何在Spring Cloud Stream中添加或调整文件供应商的配置
How to add or adjust the configuration of the file supplier in Spring Cloud Stream
Spring Cloud Stream 的文件供应商依赖项包括 FileSupplierConfiguration
配置文件消息源(来自 Spring 集成)。我需要自定义此 @Configuration 提供的 FileReadingMessageSource
,但我不确定这样做的最佳方式。它只提供基本属性来控制它的 @Bean
s,但我需要更多。
我考虑过将 FileSupplierConfiguration
从应用程序中排除,但我必须将其中的大部分代码复制到我自己的 @Confguration class 中。显然,这是一个不太理想的解决方案。
那么如何自定义文件消息源,例如使用额外的 FileListFilter
s?
添加一个BeanPostProcessor
@Bean,像这样:
@Bean
public BeanPostProcessor inboundFileAdaptorCustomizer() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof FileInboundChannelAdapterSpec) {
//add filter function here
((FileInboundChannelAdapterSpec) bean).filter(files -> ...);
}
return bean;
}
};
}
Spring Cloud Stream 的文件供应商依赖项包括 FileSupplierConfiguration
配置文件消息源(来自 Spring 集成)。我需要自定义此 @Configuration 提供的 FileReadingMessageSource
,但我不确定这样做的最佳方式。它只提供基本属性来控制它的 @Bean
s,但我需要更多。
我考虑过将 FileSupplierConfiguration
从应用程序中排除,但我必须将其中的大部分代码复制到我自己的 @Confguration class 中。显然,这是一个不太理想的解决方案。
那么如何自定义文件消息源,例如使用额外的 FileListFilter
s?
添加一个BeanPostProcessor
@Bean,像这样:
@Bean
public BeanPostProcessor inboundFileAdaptorCustomizer() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof FileInboundChannelAdapterSpec) {
//add filter function here
((FileInboundChannelAdapterSpec) bean).filter(files -> ...);
}
return bean;
}
};
}