Jonly_721 2016-01-25 15:31 采纳率: 0%
浏览 2440

用idea15开发 springmvc项目时报404错误,求大神告知原因

web.xml配置如下:

rest
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
/WEB-INF/rest-servlet.xml

1


rest
/restful/*

    rest-servlet.xml配置如下:
    <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="  
    http://www.springframework.org/schema/beans       
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/context   
    http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">


<description>Spring MVC for Restful</description>
<!--检测注解 -->
<context:component-scan base-package="com.onlyyou.java.controller" />
<context:annotation-config />  
<mvc:annotation-driven />
<mvc:default-servlet-handler/>
</beans>

Controller代码如下:
@Controller

@RequestMapping("/hello")
public class HelloController {
@RequestMapping(value="/user", method= RequestMethod.GET)
@ResponseBody
public UserBean testParam(@RequestParam("username") String name) {
UserBean userBean = new UserBean();
userBean.setAvatar("123");
userBean.setBirthday("323");
userBean.setCensusRegister("dfda");
return userBean;

}

}
最后再浏览器访问http://localhost:6080/onlyyou/restful/hello/user?username=tom报404的错误

  • 写回答

3条回答

  • Jonly_721 2016-01-25 15:34
    关注

    重新粘贴一下代码,web.xml如下:
    <?xml version="1.0" encoding="UTF-8"?>
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">

    contextConfigLocation
    /WEB-INF/applicationContext.xml


    org.springframework.web.context.ContextLoaderListener

    <servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/rest-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/restful/*</url-pattern>
    </servlet-mapping>
    

    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿