问题
firstly,thanks for attention
i defined ftp adapter in my spring integration project and used mv
command to move files in ftp server,directory structure is:
ftp-root
-----------Directory1\
-----------------in\
---------------------------file.in
-----------------out\
i want to move file file.in
in ftp-root\Directory1\in\
directory to move ftp-root\Directory1\out\
with .out.rpt
extension ftp-root\Directory1\out\a.out
i used int-ftp:outbound-gateway
adapter to run mv
command on ftp server,my code is:
<int-ftp:outbound-gateway id="gatewayMv"
session-factory="ftpSessionFactory"
expression="payload.remoteDirectory + '/' + payload.filename"
request-channel="mvChannel"
command="mv"
rename-expression="payload.remoteDirectory + '/' + payload.filename "
reply-channel="aggregateResultsChannel"/>
how to use SpEL expression to replace in
with out
in rename-expression option?
回答1:
rename-expression="payload.remoteDirectory + '/' + payload.filename.replaceFirst('in', 'out')"
In most cases SpEL work like the regular Java. Since filename
is a String
you can apply for it any string operation.
回答2:
thanks for @Artem Bilan ane @Gary for answer
the other way to working with string
define a bean as bellow :
public class StringUtil {
public String replacement(String value,String var1,String var2) {
return value.replace(var1,var2);
}
}
and in expression option set to:
rename-expression="@stringUtil.replacement(payload.remoteDirectory + '/' + payload.filename,'in','out')"
来源:https://stackoverflow.com/questions/29790624/how-to-replace-string-in-spel-expression