Search code examples
spring-bootspring-integrationspring-autoconfiguration

Spring Integration configuration with Spring Boot


I'm trying to be able to configure Spring Integration defaults via Spring Boot's Third-party Configuration mechanism.

I've tried:

@Configuration
@EnableIntegration
class IntegrationFlowConfigration {
  ...

  // @Primary to hopefully take precedence
  @Primary
  // The name could also be set to IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME
  @Bean(name = {"integrationGlobalProperties"})
  // Ideally, I'd use IntegrationProperties.INTEGRATION_PROPERTIES_PREFIX, but it ends with '.'
  @ConfigurationProperties(prefix = "spring.integration")
  static IntegrationProperties integrationGlobalProperties() {
    return new IntegrationProperties();
  }

  ...
}

In this way, I'd be able to create a spring.integration section in my application.yaml file, where all of the rest of my Spring Boot properties are specified.

However, those properties in my application.yaml file are completely ignored.

The only mechanism that allows configuration defaults seems to be creating a META-INF/spring.integration.properties file.

For reference, I'm using:

  • Spring Boot: 3.3.4
  • Spring Integration: 6.3.4

Any suggestions?

Thanks!


Solution

  • Spring Integration comes with an auto-configuration in Spring Boot. And there is indeed an org.springframework.boot.autoconfigure.integration.IntegrationProperties configured for us against spring.integration prefix: https://docs.spring.io/spring-boot/appendix/application-properties/index.html#application-properties.integration.spring.integration.channel.auto-create.

    Therefore there is no need in trying to handle it as a third-party, since there is just on one for us.

    And looks like that's exactly what is confirmed by your experience. That META-INF/spring.integration.properties is read by the IntegrationPropertiesEnvironmentPostProcessor from Spring Boot and populated to the org.springframework.boot.autoconfigure.integration.IntegrationProperties.

    While your integrationGlobalProperties does nothing because those spring.integration props cannot be mapped properly to the org.springframework.integration.context.IntegrationProperties.