【问题标题】:"NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector" in Spring Security OAuth after upgrading from Spring 4.3 to 5.0从 Spring 4.3 升级到 5.0 后 Spring Security OAuth 中的“NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector”
【发布时间】:2018-12-29 05:36:09
【问题描述】:

我正在尝试将项目从 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 兼容的版本?如果是这样,我有什么选择?

【问题讨论】:

  • 解决这个问题好运吗?
  • 不,@TerNovi。自从发帖以来,我一直被转移到其他工作上。但我最终会回到这项工作,如果我取得任何进展,我会发布更新。

标签: spring spring-security spring-security-oauth2


【解决方案1】:

正如类的 javadoc 中的 spring 所示,从 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 版迁移指南中所述:

在代码库中删除了许多不推荐使用的类和方法。

What's New in Spring Framework 5.x

【讨论】:

    【解决方案2】:

    Spring Security OAuth 2.3.3 已经过测试up to Spring Security 5.0.3。 (您可以尝试使用列出的依赖项 herehere,只是为了在您研究时消除噪音。)

    也就是说,Spring Security OAuth2 Autoconfig 项目 builds against Spring Boot 2.1.0,它使用 Spring Security 5.1.0 和 Spring Security OAuth 2.3.4,所以我预计不会出现任何不可避免的类路径问题。

    如果您还没有,那么值得仔细检查您的依赖关系树,看看是否有任何意外的依赖关系。

    或者,如果您可以用最少的样本重现它,您可以发布它 - 这可能会使问题更清晰。

    最后,Spring Security 5.x 系列发布了一个全新的、完全集成的 OAuth 模块,它将 Spring Security OAuth 插件库置于维护模式。您可以跟踪feature diff 以查看 5.1 是否具有您需要能够删除插件的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-14
      • 2018-04-15
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 2016-11-25
      • 1970-01-01
      • 2023-02-23
      相关资源
      最近更新 更多