java - Spring Integration FtpOutboundGateway setLocalDirectory 与系统属性和#remoteDirectory

标签 java spring ftp spring-integration spring-el

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

属性.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")

关于java - Spring Integration FtpOutboundGateway setLocalDirectory 与系统属性和#remoteDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51682862/

相关文章:

java - codehaus 关闭后 : http://enunciate. codehaus.org/schemas/enunciate-1.27.xsd 的新位置是什么?

java - 从 JSch 中的命令输出中删除 shell 内容(如提示)

ftp - 有没有办法列出 ftp 中本地目录的内容?

javascript - 广告链接网站

sockets - FTP 主动模式和多​​路复用

java - 如何在 Java 中实现 OpenID

java - 如何使 Jpanel 的所有区域可拖动,包括其中的 JSVGCanvas

java - 在 Spring mvc 中使用 html 文件发送 dto

java - 使用 Hibernate 和 Spring 创建 Blob

java - JPA CriteriaQuery 实现 Spring Data Pageable.getSort()