我正在使用 intellij
和 spring-boot
来构建服务器应用程序。但它经常显示 404 URI not found 错误
。特别是当我在类中声明 @RequestMapping
时。
错误
{
"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);
}
}
服务器日志
Mapped "{[/profile],methods=[GET]}" onto public ....
注意:ProfileController
的封装有多层。就像com.company.project.modules.profiles.controller
一样,其中com.company.project
包包含Application
。我尝试了 @ComponentScan 但没有帮助。同时使 IDE 缓存
无效。
最佳答案
您应该在 RequestMapping 中使用“值”而不是“名称”:
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
关于java - 找不到 URI 404 Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48873265/