我有一个应用程序,可以通过 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/