0

Can I do something like this?

private final static String myVar = "health.xyz.throughput";

@Value("${{myVar}:10}")   // doesn't work of course
private Integer healthThroughput;

Essentially myVar key is getting used elsewhere so wanted to see if it can be moved to a constant?

90abyss
  • 7,037
  • 19
  • 63
  • 94
  • Related: https://stackoverflow.com/questions/10636201/java-annotations-values-provided-in-dynamic-manner – Hulk Apr 20 '23 at 04:51

1 Answers1

1

Yes its possible:

  private static final String myVar = "health.xyz.throughput";

  @Value("${" + myVar + ":10}")
  private Integer healthThroughput;

Also you can use:

  private static final String myVar = "${health.xyz.throughput:10}";

  @Value(myVar)
  private Integer healthThroughput;
gurkan
  • 509
  • 1
  • 4
  • 18