Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Spring Integration using XML vs Java DSL?

What are the advantages of Spring Integration using XML over using Java DSL? I find that all docs are written using XML declarative format, however, I personally find it easier to write Java code rather than XML. Is there any reason for reconsidering my view point?

like image 878
Alan Sereb Avatar asked Mar 20 '26 07:03

Alan Sereb


1 Answers

There is no "difference" at runtime; only XML was available originally; we are adding more DSL examples to the docs/samples over time. e.g. https://docs.spring.io/spring-integration/reference/html/sftp.html#configuring-with-the-java-dsl

@SpringBootApplication
public class SftpJavaApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(SftpJavaApplication.class)
            .web(false)
            .run(args);
    }

    @Bean
    public IntegrationFlow sftpInboundFlow() {
        return IntegrationFlows
            .from(Sftp.inboundAdapter(this.sftpSessionFactory)
                    .preserveTimestamp(true)
                    .remoteDirectory("foo")
                    .regexFilter(".*\\.txt$")
                    .localFilenameExpression("#this.toUpperCase() + '.a'")
                    .localDirectory(new File("sftp-inbound")),
                 e -> e.id("sftpInboundAdapter")
                    .autoStartup(true)
                    .poller(Pollers.fixedDelay(5000)))
            .handle(m -> System.out.println(m.getPayload()))
            .get();
    }
}
like image 76
Gary Russell Avatar answered Mar 21 '26 19:03

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!