Java 使用FileWritingMessageHandler的资源加载程序
当为Java 使用FileWritingMessageHandler的资源加载程序,java,spring,spring-integration,Java,Spring,Spring Integration,当为端点使用目录表达式时,在org.springframework.integration.file.FileWritingMessageHandler上调用以下方法: 专用文件EvaluatedTestionDirectoryExpression(消息){ 最终文件目标目录; 最终对象destinationDirectoryToUse=this.destinationDirectoryExpression.getValue( 这是一种新方法(evaluationContext、message)
端点使用目录表达式时,在org.springframework.integration.file.FileWritingMessageHandler上调用以下方法:
专用文件EvaluatedTestionDirectoryExpression(消息){
最终文件目标目录;
最终对象destinationDirectoryToUse=this.destinationDirectoryExpression.getValue(
这是一种新方法(evaluationContext、message);
if(destinationDirectoryToUse==null){
抛出新的IllegalStateException(String.format)(“提供的”+
“destinationDirectoryExpression(%s)不能解析为null。”,
this.destinationDirectoryExpression.getExpressionString());
}
else if(目标目录使用字符串的实例){
最终字符串destinationDirectoryPath=(字符串)destinationDirectoryToUse;
Assert.hasText(destinationDirectoryPath,String.format(
“无法解析所提供表达式“%s”的目标目录名。”,
this.destinationDirectoryExpression.getExpressionString());
destinationDirectory=新文件(destinationDirectoryPath);
}
else if(目标目录使用文件实例){
destinationDirectory=(文件)destinationdirectorytoose;
}否则{
抛出新的IllegalStateException(String.format)(“提供的”+
“destinationDirectoryExpression(%s)的类型必须为”+
“java.io.File或是字符串。”,this.destinationDirectoryExpression.getExpressionString());
}
validateDestinationDirectory(destinationDirectory,this.autoCreateDirectory);
返回目的地董事会;
}
根据这段代码,我看到如果要使用的目录计算为字符串,它将使用该字符串创建一个新的java.io.File
对象
是否有原因不能/不应该使用ResourceLoader而不是直接创建新文件?
我这样问是因为我的表达式的计算结果是file://path/to/file/'这当然是java.io.File(String)
构造函数的无效路径。我曾假设Spring处理字符串的方式与处理
上的目录属性的方式相同,并将其传递给ResourceLoader
摘录自我的配置文件:
其中,baseDirectory
是一个属性,它根据表单的环境而变化file://hostname/some/path/“虽然我没有直接回答这个问题,但我想发布我使用的解决方法
在XML配置中,我更改了目录表达式
,以通过DefaultResourceLoader
而不是字符串计算为文件
这就是我的新配置:
这种情况没有特别的原因,可能只是在实施时没有考虑到
对我来说,这个请求听起来很合理,通过提供更简单的语法,它将使其他人受益(即使您已经找到了解决方法)。请打开一个;谢谢。你能把这个答案扩大一点吗?现在,这似乎是一个边缘,而不是一个答案。你能解释一下为什么需要一张罚单吗,或者对当前的实现有什么理由吗;我希望这样更好;