Spring 将 FtpOutboundGateway setLocalDirectory 与系统集成 属性 和 #remoteDirectory

Spring Integration FtpOutboundGateway setLocalDirectory with system property and #remoteDirectory

我有一个应用程序通过 FTP 将内容拉入本地文件系统,其中位置由系统定义 属性:

Properties.java:

public static final String STORAGE_PATH = "${project.storage-path}";

FtpConfiguration.java:

@Value(Properties.STORAGE_PATH)
private String storagePath;

@Value(Properties.STORAGE_PATH + "/FTP")
private String ftpStoragePath;

@MessagingGateway(defaultRequestChannel = "ftpChannel")
public interface Gateway {
    public List<File> fetchFiles(String ftpDirectory);
}

@Bean
@ServiceActivator(inputChannel = "ftpChannel")
public FtpOutboundGateway gateway() {

    FtpOutboundGateway gateway = new FtpOutboundGateway(sessionFactory(), "mget", "payload");

    gateway.setOptions("-R");
    gateway.setLocalDirectoryExpression(new SpelExpressionParser().parseExpression("ftpStoragePath+#remoteDirectory"));

    return gateway;
}

我需要将内容复制到本地文件系统,从 STORAGE_PATH 开始附加“/FTP”,同时保留远程 FTP 文件系统上的层次结构(使用 #remoteDirectory) .我正在尝试文档中有意义的所有变体:

.parseExpression("ftpStoragePath+#remoteDirectory")
.parseExpression("${ftpStoragePath}+#remoteDirectory")
.parseExpression(ftpStoragePath+"+#remoteDirectory")

等...

我想不出 SpelExpressionParser 的正确语法。如果我对 ftpStoragePath 的值进行硬编码,它会起作用,但这显然不适用于自定义部署。当计划任务调用以下时产生错误:

FtpTaskSync.java:

List<File> files = AppContextUtils.getBean(Gateway.class).fetchFiles("/*");

这是调用 .fetchFiles() 时抛出的错误:

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'ftpStoragePath' cannot be found on object of type 'org.springframework.messaging.support.GenericMessage' - maybe not public or not valid?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)

SPEL 字符串的不同变体会引发不同的错误。我进行了广泛的搜索,但找不到另一个做类似事情的例子,这可能吗?

你的最后一个例子很接近,但你需要使 属性 值从 SpEL 的角度来看是一个文字;像...

.parseExpression("'" + this.ftpStoragePath + "'" + "#remoteDirectory")