Spring3.2 Contorller单元测试参数问题: java.lang.NoSuchMethodException
2014-05-19 18:31
549 查看
使用3.2做单元测试的时候发现这个问题,因为之前都是用3.0中的配置适配器使用AnnotationMethodHandlerAdapter,到3.2中升级为RequestMappingHandlerAdapter;
运行之前的单元测试发现报异常:java.lang.NoSuchMethodException,看了一下堆栈发现反射调用的方法签名明显不对,于是看了一下调用的代码,
之前是:handlerAdapter.handle(request, response, new HandlerMethod(controller, "setClassBreaksInfo"))
感觉是这里的问,继续看handle的参数,发现还有一个Class<?>... parameterTypes,预计根据这里还匹配调用参数签名的,于是改为跟调用方法签名对应的ClassType,然后可以正确运行了,整体配置如下:
配置文件
运行之前的单元测试发现报异常:java.lang.NoSuchMethodException,看了一下堆栈发现反射调用的方法签名明显不对,于是看了一下调用的代码,
之前是:handlerAdapter.handle(request, response, new HandlerMethod(controller, "setClassBreaksInfo"))
感觉是这里的问,继续看handle的参数,发现还有一个Class<?>... parameterTypes,预计根据这里还匹配调用参数签名的,于是改为跟调用方法签名对应的ClassType,然后可以正确运行了,整体配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:annotation-config /> <context:component-scan base-package="com.catt.action" /> <bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="webBindingInitializer"> <bean class="util.web.springmvc.BindingInitializer"/> </property> </bean> <bean class="util.web.springmvc.ExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">/error/500</prop> </props> </property> </bean> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="util.web.interceptor.AdminLoginInterceptor"> <property name="loginUrl" value="/login.jsp"/> <property name="excludeUrls"> <list> <value>/safeMgr/login.do</value> <value>/safeMgr/sendRedirectLogin.do</value> <value>/gisAction/getRenderKpi.do</value> <value>/gisAction/createDataSource.do</value> <value>/gisAction/getClassBreaksInfo.do</value> <!-- 以上GIS和登陆配置是必须的 --> </list> </property> </bean> </mvc:interceptor> </mvc:interceptors> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> <bean id="SpringBeanUtil" class="util.SpringBeanUtil" /> <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> </beans>
配置文件
相关文章推荐
- Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:问题解决
- spring的aop拦截action中的方法会报java.lang.NoSuchMethodException: $Proxy97.test()异常
- 问题二20150511——jar包冲突(报java.lang.NoSuchMethodException)
- spring No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.mo
- Spring Boot常见问题(二)Unable to start embedded container; nested exception is java.lang.NoSuchMethodErro
- Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:问题解决
- java.lang.NoSuchMethodException: [org.springframework.web.multipart.MultipartFile;.<init>()
- spring报错 :java.lang.NoSuchMethodException: <init>()
- Java之——java.lang.NoSuchMethodException: [org.springframework.web.multipart.MultipartFile;.<init>()
- spring(错误一) spring mvc上传多张图片,报错:java.lang.NoSuchMethodException解决方案
- springBoot整合myBatis错误:java.lang.NoSuchMethodException
- URL重写:urlrewrite 出现 java.lang.NoSuchMethodException: 错误
- java.lang.NoSuchMethodException 解决办法
- java.lang.NoSuchMethodException 解决办法
- 在使用hibernate 和spring 构架的框架中如果出现Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm
- java.lang.NoSuchMethodException: 解决办法
- 在Spring中发现java.lang.ClassCastException: $Proxy1问题解析
- org.zkoss.zk.ui.UiException: java.lang.NoSuchMethodException:
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException: Action[/role] does not contain specified method (check logs)紧急求救~