-1
Given:
application.yml --> content

kafka:
  topicA: topic-a
  topicB: topic-b


public enum KafkaTopicBeanMapping {
    TOPICA(@Value("${kafka.topicA}", "ratelimiterABean"));
    TOPICB(@Value("${kafka.topicB}", "ratelimiterBBean"));

    private final String topicName;
    private final String ratelimiterBeanName;
}

But in the above case, I am getting error that @Value("${kafka.topicA}") cannot be used here. I don't want to put ratelimiterBeanName as part of application.yml. Is there a way to achieve this?

Noob
  • 174
  • 1
  • 2
  • 19

1 Answers1

1

Java Enums are static in nature, they can be initialized only once. @Value in Spring makes values dynamic in nature which enums are not capable of.

vaibhavsahu
  • 612
  • 2
  • 7
  • 19