The problem is that up to Spring version 5.3.x, HttpMethod
used to be an enum
( https://github.com/spring-projects/spring-framework/blob/5.3.x/spring-web/src/main/java/org/springframework/http/HttpMethod.java#L33 ):
public enum HttpMethod {
But they changed in in Spring Version 6.x to a "normal" class ( https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/HttpMethod.java#L37 ):
public final class HttpMethod implements Comparable<HttpMethod>, Serializable {
The reason for this change is given as
Refactor HTTP Method from Enum to Class
This commit refactors HttpMethod from a Java enum into a class. The underlying reason being that HTTP methods are not enumerable, but instead an open range and not limited to the predefined values in the specifications.
While you can use enum constants in a switch
statement, you cannot use instances of normal classes.
Therefore if you want to use Spring version 6.x you must rewrite your switch(method)
to an if ()
- else if ()
chain or use specific request mappings for the different methods.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.