Spring 当驼峰路线中的move=null时会发生什么情况?
在我的Spring Camel应用程序中,我尝试根据Spring 当驼峰路线中的move=null时会发生什么情况?,spring,apache-camel,Spring,Apache Camel,在我的Spring Camel应用程序中,我尝试根据destinationFolder属性移动或删除文件。如果destinationFolder=null,我希望删除该文件。如果destinationFolder=null,我希望将文件移动到destinationFolder String destinationFolder; //In the Camel routeBuilder: from("file://C:/folder1?move=" + destinationFolder) de
destinationFolder
属性移动或删除文件。如果destinationFolder=null
,我希望删除该文件。如果destinationFolder=null
,我希望将文件移动到destinationFolder
String destinationFolder;
//In the Camel routeBuilder:
from("file://C:/folder1?move=" + destinationFolder)
destinationFolder中将发生的情况为null?文件是否移动到默认位置
当我设置destinationFolder=null时,我看到文件在folder1中被删除。首先,您应该知道何时使用“move”、“delete”和“noop”,以及它在Apache中的工作方式 注意:1)如果目标路径不存在,则文件将自动删除。 注意:2)如果在驼峰URL中未使用“noop=true”,则文件将被删除(如果目标路径为空) 参考资料:- 基本测试代码:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class SFTPTest {
public static void main(String[] args) throws Exception {
DefaultCamelContext ctx = null;
try{
ctx = new DefaultCamelContext();
ctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
String filepath = "file:///camelexample/?fileName=test.txt&move=null";
from(filepath)
.log("File processed");
}
});
ctx.start();
Thread.sleep(5000);
ctx.stop();
}catch (Exception e){
System.err.println("Exception is : "+e.getLocalizedMessage());
}finally {
try{
ctx.stop();
}catch (Exception e){
System.err.println("Exception is : "+e.getLocalizedMessage());
}
}
}
}
如果设置了移动选项,则文件组件将移动文件,不能将其设置为
null
,然后让其自动删除文件。默认情况下,文件被移动到名为.camel
的文件夹中
因此,要么设置delete=true,要么设置move to some folder name来移动文件。在您的链接中,我没有看到他们说如果目标路径为null,文件将被删除。你能指出他们在文件的什么地方说的吗?我只是想确认一下。他们没有提到文档中的任何位置。如果目标路径为空,它基本上会删除文件。我分享了这个链接供你将来参考。非常感谢。