org.springframework.http.HttpMethod はクラスとなり、列挙型ではなくなった。

このルールは org.springframework.http.HttpMethod コードでは enum.

Spring Framework 6、 org.springframework.http.HttpMethod は列挙型から標準クラスにリファクタリングされた。 などの一般的に使用される定数に対し HttpMethod.GET および HttpMethod.POST がまだ利用可能な場合、列挙型固有の機能に依存するコードはコンパイルできなくなるか、実行時に失敗する。

を置き換えるなど、開発者はコードをクラス互換性のある代替物に移行しなければなりません EnumSet<HttpMethod> への Set<HttpMethod> および switch との記述がある if-else をブロックする。

次の例は、フラグが立てられる無効な使用法を示している:


import org.springframework.http.HttpMethod;
import java.util.EnumSet;
public class InvalidHttpMethodUsage {
private EnumSet<HttpMethod> methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
    public void handle(HttpMethod method) {
    switch (method) {
          case GET:
              System.out.println("GET");
              break;
        }
    }
}

次の例は、移行された有効な使用法を示している:


import org.springframework.http.HttpMethod;
import java.util.Set;
public class ValidHttpMethodUsage {
private Set<HttpMethod> methods = Set.of(HttpMethod.GET, HttpMethod.POST);
    public void handle(HttpMethod method) {
    if (HttpMethod.GET.equals(method)) {
     System.out.println("GET");
        }
    }
}

詳しくは、以下のリソースを参照してください。