我正在使用Spring 4.2.0.RELEASE并尝试使用WebArgumentResolver
但无法理解我案例的行为。我提供了两个自定义注释。
我的控制器有以下映射:
@RequestMapping
public ModelAndView install(@AppFromId final App app, @JsonBody final Map postBody)
MyArgumentResolver:
public class MyArgumentResolver implements WebArgumentResolver {
private static final Logger logger = LoggerFactory.getLogger(AppArgumentResolver.class);
@Override
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest nativeWebRequest) throws Exception {
String methodName = methodParameter.getMethod().getName();
int parameterIndex = methodParameter.getParameterIndex();
logger.info("Method-name: {}, parameter-index: {}, methodParamClass: {}", methodName, parameterIndex, methodParameter.getParameterType().getSimpleName());
for (Annotation annotation : annotations) {
logger.info("Resolving annotation: {}", annotation.annotationType().getSimpleName());
}
return UNRESOLVED;
}
}
当我调用控制器方法时,MyArgumentResolver
会记录以下内容:
方法名:installApp,参数索引:0,methodParamClass:App 解析注释:AppFromId
context.xml文件
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="../MyArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>
我的问题是,为什么控制器方法的第二个参数(@JsonBoyd final Map postBody
)未被MyArgumentResolver
解析/检查?