没有用于处理程序异常的适配器 [英] No adapter for handler exception

查看:64
本文介绍了没有用于处理程序异常的适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring MVC框架开发Web应用程序.我想同时基于注释和beanName进行URL映射.

I'm developing a web application using spring mvc framework. I want to to both annotation and beanName based url mappings.

我的上下文文件中具有以下配置

I've the following configurations in my context file

<mvc:annotation-driven />

<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>

我基于注释的控制器工作正常,但是基于beanNamed的url映射抛出异常没有用于处理程序的适配器".

My annotation based controllers are working fine but beanNamed based url mapping are throwing the exception "No adapter for handler".

我在做什么错了?

谢谢

推荐答案

默认情况下,spring mvc定义了3个不同的请求处理程序适配器,它们是

By default the spring mvc defines 3 different request handler adapters, they are

org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

因此您不必在上下文文件中定义它们,但是如果您在上下文文件中定义至少一个处理程序适配器,spring将不会创建默认适配器.

So you need not have to define them in your context file, but if you define at least one handler adapter in your context files, spring will not create the default adapters.

根据

In your configuraion you are using <mvc:annotation-driven />, according to this spring documentation this will cause the context to define both DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter. Since we are creating the AnnotationMethodHandlerAdapter in our context definition spring will not create the other two handlerAdapters. That is why you are getting the said exception.

beanNameUrlMapping需要handlerAdapter SimpleControllerHandlerAdapter.

The beanNameUrlMapping needs the handlerAdapter SimpleControllerHandlerAdapter.

要解决此异常,您只需在上下文中创建一个类型为"SimpleControllerHandlerAdapter"的新bean.

To resolve this exception you can simply create a new bean of type "SimpleControllerHandlerAdapter" in your context.

<bean
    class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter">
</bean>

这篇关于没有用于处理程序异常的适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆