网页
综合
更新时间 2026-11-13 15:37:00
https://spring.io/blog/2022/01/06/introducing-spring-integration-groovy-dsl/
自动蜘蛛
spring.io
正文约 4212 字
Happy New Year, Spring community!
Hope you had great holidays and ready for new excitements in front of us.
After the rest and recharging during Christmas break I decided to pay honor to my favorite language back in days - Groovy.
And now it’s my pleasure to present you a brand new Groovy DSL for Spring Integration. You perhaps heard about our old attempt to make a Groovy DSL on top of Spring Integration XML support. But the solution was pretty cumbersome (especially for protocol-specific channel adapters) and support burden has grown tremendously. This my latest implementation is fully based on already mature Java DSL and its builder pattern support.
Having 10 years experience with Gradle I thought that it is going be easy enough for me to prepare quickly something what just extends an IntegrationFlowDefinition and exposes a Groovy builder style for definition. Turns out just using a language and engineering a DSL on top of it are different tasks, and I had to start learning respective Groovy aspects from a scratch. A series of blog posts by Vladimír Oraný gave me a good source of information what and how should be used and done to make end-user experience with Groovy DSL as best as possible.
Including the current success of existing Kotlin DSL for Spring Integration, so far I ended up with a couple Groovy classes. The IntegrationGroovyDsl as a factory for static integrationFlow() methods to be imported to the target project and delegation to the well-knows IntegrationFlows.from() factories. And the GroovyIntegrationFlowDefinition as a wrapper around IntegrationFlowDefinition delegate. Both classes heavily leverage a Groovy first class citizen - groovy.lang.Closure, with a @DelegatesTo and @ClosureParams features to support IDE suggestions and auto-completion.
So, all you need is to have a org.springframework.integration:spring-integration-groovy-dsl:0.0.1 dependency, add an import static org.springframework.integration.dsl.IntegrationGroovyDsl.integrationFlow and start typing your IntegrationFlow bean in a nice Groovy style. And this is how it looks so far in my IntelliJ IDEA:
After learning those @DelegatesTo and @ClosureParams, I realized that Kotlin also provides a nice feature for better IDE experience. So, the next Spring Integration 5.5.8 version (due to in the middle of January) also includes an @IntegrationDsl marker annotation.
You can find more samples in the project README and respective Spock tests. If project matures, eventually it may go directly to spring-integration-core. We also may override those IntegrationGroovyDsl and GroovyIntegrationFlowDefinition Groovy classes to Java (it’s just a DSL API anyway!), however I believe the @CompileStatic Groovy feature should be enough to optimize compiled byte code in the end.
Give it a try and any feedback is welcome!
Project Page | GitHub Issues | Contributing | Help | Chat
Stay connected with the Spring newsletter
VMware offers training and certification to turbo-charge your progress.
TrueSource Spring Enterprise offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.
Check out all the upcoming events in the Spring community.
Copyright © 2005 - 2026 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. Terms of Use • Privacy • Trademark Guidelines
Apache®, Apache Tomcat®, Apache Kafka®, Apache Cassandra™, and Apache Geode™ are trademarks or registered trademarks of the Apache Software Foundation in the United States and/or other countries. Java™, Java™ SE, Java™ EE, and OpenJDK™ are trademarks of Oracle and/or its affiliates. Kubernetes® is a registered trademark of the Linux Foundation in the United States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other countries. Windows® and Microsoft® Azure are registered trademarks of Microsoft Corporation. “AWS” and “Amazon Web Services” are trademarks or registered trademarks of Amazon.com Inc. or its affiliates. All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes. Other names may be trademarks of their respective owners.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。