Spring Boot 对文件端点使用自定义processStrategy

wd2eg0qa  于 2023-02-16  发布在  Spring
关注(0)|答案(1)|浏览(111)

我创建了一个自定义的processStrategy,它是GenericFileDeleteProcessStrategy的扩展:

@Component
public class AlwaysDeleteProcessStrategy<T> extends GenericFileDeleteProcessStrategy<T> {

    private static final Logger LOGGER = LoggerFactory.getLogger(AlwaysDeleteProcessStrategy.class);

    @Override
    public void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
        LOGGER.info("Deleting file despite exception");
        super.commit(operations, endpoint, exchange, file);
    }
}

当在endpoint-dsl中使用它时,它工作得非常好,但是当我用String构建端点时,它就停止工作了:

//Works fine
from(file("src/test/resources/input").advanced().processStrategy(new AlwaysDeleteProcessStrategy()))  

//Doesn't work
from("file://src/test/resources/input?processStrategy=#alwaysDeleteProcessStrategy")

这是我尝试将其添加到String端点时抛出的异常:

Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: alwaysDeleteProcessStrategy of type: org.apache.camel.component.file.GenericFileProcessStrategy
    at org.apache.camel.support.CamelContextHelper.mandatoryLookupAndConvert(CamelContextHelper.java:253)
    at org.apache.camel.support.EndpointHelper.resolveReferenceParameter(EndpointHelper.java:376)
    at org.apache.camel.support.EndpointHelper.resolveReferenceParameter(EndpointHelper.java:336)
    at org.apache.camel.support.component.PropertyConfigurerSupport.property(PropertyConfigurerSupport.java:55)
    at org.apache.camel.component.file.FileEndpointConfigurer.configure(FileEndpointConfigurer.java:131)
    at org.apache.camel.support.PropertyBindingSupport.setSimplePropertyViaConfigurer(PropertyBindingSupport.java:733)
    ... 43 common frames omitted

我也尝试过手动创建bean,因为@Component注解还不够,但是没有什么效果。我怎样才能让这两种情况都能工作呢?

92dk7w1h

92dk7w1h1#

是否向注册表中添加了AlwaysDeleteProcessStrategy的示例?

getContext().getRegistry().bind("alwaysDeleteProcessStrategy", new AlwaysDeleteProcessStrategy());

相关问题