Search code examples
springspring-bootspring-integrationspring-integration-http

@EnableConfigurationProperties(MyConfig.class) generated bean name does not work in spring-integration


I have a config class with @ConfigurationProperties as follows. I am able to populate systemConfigMap from application.yaml in the MyConfig class as seen below

@ConfigurationProperties(prefix = "my-config")
@ConstructorBinding
@AllArgsConstructor
public class MyConfig {

    /**
     * A Configuration Map of multiple Systems
     */
    private Map<String, SystemConfig> systemConfigMap;
    
}

the main class as

@EnableConfigurationProperties(MyConfig.class)
public class SpringApp {
    public static void main(String[] args) {
        SpringApplication.run(SpringApp.class, args);
    }
}

The problem is that the generated bean name is my-config-a.b.c.config.MyConfig, which I am not able to use in payload-expression on spring integration http inbound gateway, I guess since it has "-" in it.

How can I specify the bean name for the generated bean MyConfig?

EDIT : HTTP Gateway Config

 <int:channel id="myConfigListChannel" />
 <int-http:inbound-gateway request-channel="myConfigListChannel"
                              path="/data"
                              error-channel="errorChannel"
                              supported-methods="GET"
                              payload-expression="@my-config-a.b.c.config.MyConfig.getSystemConfigMap().values()"
    />

I want to load the systemConfigMap values when /data is requested to start processing the flow.


Solution

  • When you try to use a complex bean id like yours my-config-a.b.c.config.MyConfig in the SpEL expression, you need to wrap it into the literal. Otherwise it understands an id until the first . which is treat as method/property reference to evaluate on a possible bean evaluate before. So, it tries to find a bean like my-config-a and then tries to get access to its b property, which is fully false in your case.

    To fix your problem you need to do like this:

     payload-expression="@'my-config-a.b.c.config.MyConfig'.systemConfigMap.values()"
    

    Another trick would be like your MyConfig injection into some bean with really meaningful bean name and use that one from the expression as a delegate.