gpt4 book ai didi

spring - 从 Spring 4.3 升级到 5.0 后 Spring Security OAuth 中的 "NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector"

转载 作者:行者123 更新时间:2023-12-01 17:19:36 27 4
gpt4 key购买 nike

我正在尝试将项目从 Spring 4.3 升级到 5.0,并遇到了 Spring Security OAuth 中似乎存在的问题。特别是以下形式的嵌套 bean 创建失败堆栈:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauth2EndpointHandlerMapping' defined in class path resource [org/springframework/security/oauth2/config/annotation/web/configuration/AuthorizationServerEndpointsConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauth2EndpointHandlerMapping' defined in class path resource [org/springframework/security/oauth2/config/annotation/web/configuration/AuthorizationServerEndpointsConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector
...
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector

似乎 org.springframework.web.method.HandlerMethodSelector 在较晚的 Spring 4.x 版本中已被弃用,然后在 Spring 5.x 中被完全删除。

我试图协同工作的实际版本是:

  • Spring 框架:5.0.6
  • Spring 安全:5.0.6
  • Spring Security OAuth:2.3.3

Spring Security OAuth 版本是最新的,所以我不确定下一步该去哪里。是否没有与 Spring 5.x 兼容的版本?如果是这样,我的选择是什么?

最佳答案

正如 spring 在该类的 javadoc 中所指出的,从版本 4.3 开始,它已被弃用。推荐使用,而不是MethodIntrospector

package org.springframework.web.method;

import java.lang.reflect.Method;
import java.util.Set;

import org.springframework.core.MethodIntrospector;
import org.springframework.util.ReflectionUtils.MethodFilter;

/**
* Defines the algorithm for searching handler methods exhaustively including interfaces and parent
* classes while also dealing with parameterized methods as well as interface and class-based proxies.
*
* @author Rossen Stoyanchev
* @since 3.1
* @deprecated as of Spring 4.2.3, in favor of the generalized and refined {@link MethodIntrospector}
*/
@Deprecated
public abstract class HandlerMethodSelector {

/**
* Select handler methods for the given handler type.
* <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
* @param handlerType the handler type to search handler methods on
* @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
* @return the selected methods, or an empty set
* @see MethodIntrospector#selectMethods
*/
public static Set<Method> selectMethods(Class<?> handlerType, MethodFilter handlerMethodFilter) {
return MethodIntrospector.selectMethods(handlerType, handlerMethodFilter);
}

}

https://github.com/spring-projects/spring-framework/blob/4.3.x/spring-web/src/main/java/org/springframework/web/method/HandlerMethodSelector.java

如版本 5 的迁移指南中所示:

Many deprecated classes and methods removed across the codebase.

What's New in Spring Framework 5.x

关于spring - 从 Spring 4.3 升级到 5.0 后 Spring Security OAuth 中的 "NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51450463/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com