@RequestParam defaultvalue does not accept enum value as a default value

annotations, enums, spring-mvc

Solution

Since it has to be a String, and it has to be a constant expression, your only real option here is to use the value that will work for `Enum.valueOf()`, since that's how this is eventually resolved.

Specifically, yours should read

@RequestParam(value = "status", required = false, defaultValue = "STATUS")

Assuming, of course, that `"STATUS"` is the string value for `StatusEnum.STATUS`.

Problem

I am using spring rest controller. Here is the code. ``` @RequestParam(value = "status", required = false, defaultValue = StatusEnum.STATUS.toString()) ``` If i use enum as a defaultValue i am getting The value for annotation attribute RequestParam.defaultValue must be a constant expression. As per my understanding it should accept enum as a default value. Please advice.

Original source