Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到请求资源状态404_Java_Xml_Spring - Fatal编程技术网

Java 未找到请求资源状态404

Java 未找到请求资源状态404,java,xml,spring,Java,Xml,Spring,我收到此错误,请帮助我解决此错误。我正在使用spring json rest。此错误主要发生在发出请求时。那么您的错误是什么?您如何提出请求?可能的重复 package com.test.controller; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import o

我收到此错误,请帮助我解决此错误。我正在使用spring json rest。此错误主要发生在发出请求时。

那么您的错误是什么?您如何提出请求?可能的重复
package com.test.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.test.dao.UserDAOImpl;
import com.test.model.User;

@Controller
@RequestMapping("/service/user/")
public class SpringRestController {

    UserDAOImpl userDAOImpl=new UserDAOImpl();

    @RequestMapping(value = "/{id}", method = RequestMethod.GET,headers="Accept=application/json")   
    public User getUser(@PathVariable int id) {
      User user=userDAOImpl.getUserById(id);
      return user;
     }

     @RequestMapping(method = RequestMethod.GET,headers="Accept=application/json")
     public List<User> getAllUsers() {
      List<User> users=userDAOImpl.getAllUsers();
      return users;
     }
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>sample</display-name>
  <servlet><servlet-name>rest</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 </servlet>
<servlet-mapping>
    <servlet-name>rest</servlet-name>
     <url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
localhost:8080/sample/service/user/