Search code examples
spring-integration

Using @EnableIntegration when multiple @Configuration classes are present


In Spring Integration, all the examples I see show @Configuration classes also annotated with @EnableIntegration.

The thing is, I am building some pretty complicated flows, and I don't like the idea of having one massive @Configuration file. I prefer to break Java projects down into packages by feature, and allow each feature to have its own @Configuration class (separation of concerns, etc.). So I'd like to do the same thing with each of my individual flows.

Do I:

  • Add @EnabledIntegration/@EnabledIntegrationManagement to all my @Configuration classes?; or
  • Only add @EnabledIntegration/@EnabledIntegrationManagement to only one of my @Configuration classes (and if so, does it matter which one?); or
  • Add @EnabledIntegration/@EnabledIntegrationManagement to my @SpringBootApplication main class?; or
  • Something else?!

Solution

  • You declare it only once per application context, as any other @Enable… in Spring. On any of your @Configuration class which contributes to the application context with Spring Integration. You don’t need it with Spring Boot, though, it does declare that one for us.