0

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.

Nikhil
  • 345
  • 2
  • 13
  • Show, please, how do you use it in that expression? And what is the goal to use it at all in the expression like that? – Artem Bilan Aug 26 '20 at 19:56
  • Added via EDIT to the question. I want to trigger the flow which starts by reading `systemConfigMap` values, externally hence added an `HTTP Inbound Gateway` only to trigger the flow and return the results. Related to https://stackoverflow.com/questions/63598100/spring-integration-block-flow-having-loop-and-multiple-http-and-async-sqs – Nikhil Aug 26 '20 at 20:05

1 Answers1

1

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thank you, that works! I did try adding the single quotes earlier but Intellij showed error, so did not run the app to test, damn. Sorry for the trouble, thanks again ! – Nikhil Aug 26 '20 at 20:17
  • Or you can just add `MyConfig` as a `@Bean` (or ``) instead of adding it to `@EnableConfigurationProperties`. – Gary Russell Aug 26 '20 at 20:18