java Spring SpEL即使在使用Spring时也不编译。表示编译器。模式已设置
我有一个SpEL表达式,我正试图将其用于FtpMessageHandler(特别是用于outputHandler.setRemoteDirectoryExpressionString("headers['" + ftpOutPath + "']");
)
通过调试,我发现这个SpEL表达式没有被编译。当编译时间到来时,SpelCompilerMode
被设置为OFF
。因此,表达式没有被编译,只是返回null
(我的FTP客户端正在尝试只写入根目录,而不是我指定的根目录)
查看Spring SpEL文档(https://docs.spring.io/spring/docs/5.3.0-SNAPSHOT/spring-framework-reference/core.html#expressions),它说为了启用SpEL编译,需要设置属性spring.expression.compiler.mode
。我这样做没有任何效果-我在我的应用程序中将spring.expression.compiler.mode
设置为immediate
。属性文件,但SpelCompilerMode
仍然是OFF
为什么会这样?我怎样才能解决这个问题
我知道有人会要求提供代码样本,但老实说,我不知道我能提供什么,因为这都是Spring内部的东西。但以下是一些相关代码的示例:
FtpMessageHandler:
@Value("${my.ftp.outPath}")
private String ftpOutPath;
@Bean
@ServiceActivator(inputChannel = "myChannel")
public MessageHandler getOutputHandle(){
FtpMessageHandler outputHandler = new FtpMessageHandler(mySessionFactory());
outputHandler.setRemoteDirectoryExpressionString("headers['" + ftpOutPath + "']");
return outputHandler;
}
应用程序。亚马尔
spring:
expression:
compiler:
mode: immediate
my:
ftp:
outPath: myPath
# 1 楼答案
我仍然不知道为什么表达式没有正确编译/编译,但是将代码更改为使用
LiteralExpression
而不是使用字符串是有效的outputHandler.setRemoteDirectoryExpression(new LiteralExpression(ftpOutPath));