简体   繁体   中英

My spring rest web service not working, I got error “org.springframework.web.servlet.PageNotFound handleNoSuchRequestHandlingMethod”

This is my controller

@Controller
public class UserController {

    @RequestMapping(value = "/user", method = RequestMethod.GET,headers="Accept=application/json")
    public @ResponseBody RegisterUser getUser() {
        RegisterUser registerUser = new RegisterUser();
        registerUser.setId(1);
        registerUser.setName("John");
        registerUser.setDob("15-04-1993");
        registerUser.setAddress("US");
        registerUser.setDepartment("IT");
        return registerUser;
    }
}

This is my spring-servlet.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
      http://www.springframework.org/schema/beans    
      http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.1.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


    <context:component-scan base-package="com.user.test" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/view/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

this is my web.xml file

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    </web-app>

when am i get the user detail then i got 404 error in my advance rest client. and i got the error in my console window is that:

Jan 08, 2017 3:02:18 PM org.springframework.web.servlet.PageNotFound handleNoSuchRequestHandlingMethod WARNING: No matching handler method found for servlet request: path '/user', method 'GET', parameters map[[empty]]

Your web.xml is not complete

**Add the following into your web.xml which creates Spring Container shared by all Servlets and Filters**


    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM