简体   繁体   中英

URI not found 404 spring boot

I'm using intellij and spring-boot to build server application. But it's frequently showing 404 URI not found error . Specially when I declare @RequestMapping in class.

Error

{
    "timestamp": 1519069359705,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/profile/5"
}

Controller

@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);
    }
}

Server Log

Mapped "{[/profile],methods=[GET]}" onto public ....

Note : ProfileController 's package has several layers. Like com.company.project.modules.profiles.controller where com.company.project package contains Application . I tried @ComponentScan but didn't help. Also invalidate IDE cache .

您应该在RequestMapping中使用“值”而不是“名称”:

@RequestMapping(value = "/{id}", method = RequestMethod.GET)

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