java - spring-mvc 运行报错 No adapter for handler
迷茫
迷茫 2017-04-17 17:22:01
[Java讨论组]

配置了DispatcherServlet的detectAllHandlerMappings属性为true;
spring-mvc.xml也有声明:


    
        
                
        
    


**访问:http://localhost:8080/demo/index 一直报错:**
javax.servlet.ServletException: No adapter for handler [com.wch.controller.UserController@20142abf]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1136)

下面是Controller部分:
package com.wch.controller;

import com.wch.entity.User;
import com.wch.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

@Resource
private IUserService userService;
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String toIndex(HttpServletRequest request, Model model)
{
    String name = (String)request.getParameter("name");
    User user = this.userService.getUser(name);
    model.addAttribute("user",user);
    return  "index";
}

}

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号