[英]URI not found 404 spring boot
我正在使用intellij
和spring-boot
来构建服务器应用程序。 但是它经常显示404 URI not found error
。 特别是当我在类中声明@RequestMapping
时。
{
"timestamp": 1519069359705,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/profile/5"
}
@RequestMapping("/profile")
@RestController
public class ProfileController {
@Autowired
private ProfileService profileService;
@RequestMapping(name = "/{id}", method = RequestMethod.GET)
public Profile get(@PathVariable("id") int id){
return profileService.get(id);
}
}
Mapped "{[/profile],methods=[GET]}" onto public ....
注意 : ProfileController
的包具有多个层。 像com.company.project.modules.profiles.controller
一样, com.company.project
包中包含Application
。 我尝试了@ComponentScan
但没有帮助。 也使IDE cache
无效。
您应该在RequestMapping中使用“值”而不是“名称”:
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.