0

I'd like to define a Spring's controller path with a path variable as:

private static final String IDS_REGEX = "[" + EnumSet.allOf(MyIdsEnum.class).stream().map(MyIdsEnum.class::getValue)
  .collect(Collectors.joining("|")) + "]";
public static final String MY_PATH = "/path/{id:" + IDS_REGEX + "]}";

And then in my controller:

 @PostMapping(value = MY_PATH, produces = MediaType.APPLICATION_JSON_VALUE)

However, IntelliJ throws an error in the PostMapping value:

Attribute value must be constant

The path is already static final, what should I have to do to turn it into a constant?

Thanks in advance

FVod
  • 2,245
  • 5
  • 25
  • 52
  • 1
    Refer this : https://stackoverflow.com/questions/16509065/get-rid-of-the-value-for-annotation-attribute-must-be-a-constant-expression-me – Sanjay Jun 25 '19 at 08:53
  • Is there a workaround to do what I'd like to? – FVod Jun 25 '19 at 09:12

1 Answers1

0

It must be a compile time constant.

A compile-time constant expression is an expression denoting a value of primitive type or a String that does not complete abruptly and is composed using only the following:

  • Literals of primitive type and literals of type String
  • Casts to primitive types and casts to type String
  • [...] operators [...]
  • Parenthesized expressions whose contained expression is a constant expression.
  • Simple names that refer to constant variables.
  • Qualified names of the form TypeName . Identifier that refer to constant variables.
Hypnotise
  • 99
  • 1
  • 5