无法解决Java Spring Boot启动项目中的响应404错误?

时间:2017-11-21 07:48:54

标签: java spring spring-mvc spring-boot

使用像这样的RestController

@RestController
public class xxxController {

@Autowired
private xxxService MyService;

@RequestMapping(value = "/addxxx", method = RequestMethod.POST)
public XxxModel additionY(@RequestBody xxmodel XyXmodel {
    return MyService.addValuexx(XyXmodel);
}

我经常收到以下错误:

Response
404
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 21 Nov 2017 07:37:53 GMT
{
    "timestamp": 1511249873832,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/"
}

1 个答案:

答案 0 :(得分:1)

如果您没有路径/的映射,则会收到该错误。

您创建的是/addxxx的映射。所以你应该调用的地址是(如果你在localhost上运行,比如端口8080)http://localhost:8080/addxxx