首页 > 解决方案 > Spring HandlerMethodSelector.selectMethods 的替代品

问题描述

我使用的是 Spring 4.2.x HandlerMethodSelector 类 - 现在正在迁移到 Spring 5.1.x。有人可以帮忙吗?我们如何在最新的 Spring 版本中替换以下代码?

final Set<Method> methods = HandlerMethodSelector.selectMethods(userType, new MethodFilter()
    {
        @Override
        public boolean matches(final Method method)
        {
            return hasRequestMappingOverrideAnnotation(method);
        }
    });

标签: javaspringspring-mvc

解决方案


HandlerMethodSelector替换为MethodIntrospector

@deprecated 自 Spring 4.2.3 起,支持广义和精炼的 {@link MethodIntrospector}

你有类似的方法可以使用

 static Set<Method> selectMethods(Class<?> targetType, ReflectionUtils.MethodFilter methodFilter)

根据过滤器选择给定目标类型的方法。


推荐阅读