今天小编在写SSM整合的时候,突然在项目启动的时候就报了下面这个错误。

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.web.servlet.handler.MappedInterceptor#2’: Unsatisfied dependency expressed through constructor parameter 2: Could not convert argument value of type [cn.beyondFlateForm.interceptor.SysInterceptor] to required type [org.springframework.web.context.request.WebRequestInterceptor]: Failed to convert value of type ‘cn.beyondFlateForm.interceptor.SysInterceptor’ to required type ‘org.springframework.web.context.request.WebRequestInterceptor’; nested exception is java.lang.IllegalStateException: Cannot convert value of type ‘cn.beyondFlateForm.interceptor.SysInterceptor’ to required type ‘org.springframework.web.context.request.WebRequestInterceptor’: no matching editors or conversion strategy found

        之前小编在做项目的时候也没有报这个错误,今天突然就报了这个错误,很神奇,而且报错信息还那么长,真是看了一遍又一遍,害。看到最后两句英文报错信息,大概知道了是类型转换错误。然后我就找“springmvc-servlet”的配置文件,里面有一个拦截器的配置,如下:

	<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/manager/backend/**"/>
            <mvc:mapping path="/dev/flatform/**"/>
            <bean class="cn.beyondFlateForm.interceptor.SysInterceptor"/>
        </mvc:interceptor>

    </mvc:interceptors>

接着找到SysInterceptor这个方法,点进去,看到代码才知道错在哪了

public class SysInterceptor {
}

        这个类是要继承一个父类HandlerInterceptorAdapter的,怪不得会出现类型转换错误呢。以后啊,敲代码的时候一定要认真仔细,千万不要因为一个小细节而浪费几十分钟的时间找一个不该出的bug。