繁体   English   中英

找不到404春季启动的URI

[英]URI not found 404 spring boot

我正在使用intellijspring-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.

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