&引用;NoClassDefFoundError:org/springframework/web/method/HandlerMethodSelector";从Spring 4.3升级到5.0后的Spring安全OAuth
我试图将一个项目从Spring4.3升级到5.0,但在SpringSecurityOAuth中遇到了一个问题。尤其是表单的嵌套bean创建失败堆栈:&引用;NoClassDefFoundError:org/springframework/web/method/HandlerMethodSelector";从Spring 4.3升级到5.0后的Spring安全OAuth,spring,spring-security,spring-security-oauth2,Spring,Spring Security,Spring Security Oauth2,我试图将一个项目从Spring4.3升级到5.0,但在SpringSecurityOAuth中遇到了一个问题。尤其是表单的嵌套bean创建失败堆栈: Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nest
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在Spring4.x的后期版本中被弃用,然后在Spring5.x中被完全删除
我正在尝试使实际版本协同工作的是:
- Spring框架:5.0.6
- 春季安全:5.0.6
- Spring Security OAuth:2.3.3
SpringSecurityOAuth版本是最新的,所以我不确定下一步该去哪里。难道没有一个版本与Spring5.x兼容吗?如果是这样的话,我的选择是什么?正如spring在类的javadoc中指出的那样,从版本4.3开始,它已被弃用。建议使用,而不是MethodIntrospector
package org.springframework.web.method;
导入java.lang.reflect.Method;
导入java.util.Set;
导入org.springframework.core.MethodIntrospector;
导入org.springframework.util.ReflectionUtils.MethodFilter;
/**
*定义用于彻底搜索处理程序方法(包括接口和父级)的算法
*类,同时还处理参数化方法以及基于接口和类的代理。
*
*@作者Rossen Stoyanchev
*@自3.1
*@在Spring 4.2.3中被弃用,支持广义和精炼的{@link MethodIntrospector}
*/
@不赞成
公共抽象类HandlerMethodSelector{
/**
*为给定的处理程序类型选择处理程序方法。
*调用方通过{@link MethodFilter}参数定义感兴趣的处理程序方法。
*@param handlerType要在其上搜索处理程序方法的处理程序类型
*@param handlerMethodFilter a{@link MethodFilter}帮助识别感兴趣的处理程序方法
*@返回所选的方法或空集
*@see method inspector#selectMethods
*/
公共静态集合selectMethods(类handlerType、MethodFilter handlerMethodFilter){
返回MethodInspector.selectMethods(handlerType,handlerMethodFilter);
}
}
如第5版迁移指南所示:
许多不推荐使用的类和方法在代码库中被删除
对弹簧安全OAuth 2.3.3进行了测试。(您可以尝试使用列出的依赖项和,以便在研究时消除噪音。) 也就是说,SpringSecurityOAuth2AutoConfig项目使用SpringSecurity5.1.0和SpringSecurityOAuth2.3.4,因此我不会预测任何不可避免的类路径问题 如果您还没有,那么应该仔细检查您的依赖关系树,看看是否存在任何意外的依赖关系 或者,如果你能用最少的样本重新制作它,你可以发布它——这可能会让问题变得更清楚
最后,SpringSecurity5.x系列发布了一个新的、完全集成的OAuth模块,它将SpringSecurityOAuth插件库置于维护模式。您可以跟踪,查看5.1是否具有删除插件所需的功能。解决此问题是否顺利?否,@TerNovi。自从担任这一职务以来,我一直忙于其他工作。但我最终会回到这项工作,如果我有任何进展,我会发布更新。
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);
}
}