Reputation: 149
When using Spring Boot, in a Java class marked @Service
, I can pull in a configured value from an application.yml
file ...
foo:
bar:
baz: value
... using @Value
...
@Value("${foo.bar.baz}")
private String fooBarBaz;
Is there a way to use a configured value where a constant is required?
@KafkaListener(topics = HERE)
public void listen(String message) {
If I substitute "${foo.bar.baz}"
for HERE
, that just puts the constant literal string there instead of reading from my application.yml
file, right?
Upvotes: 0
Views: 2226
Reputation: 1130
You can try using a SpEL expression such as:
@KafkaListener(topics = "#{${foo.bar.baz}}")
public void listen(String message) {
Cf: https://github.com/spring-projects/spring-kafka/issues/361#issuecomment-313200577
Upvotes: 2