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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条