java - 找不到 URI 404 Spring Boot

标签 java spring-boot intellij-idea

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

相关文章:

java - 不使用响应 bean 的 Rest API 消费

windows-7 - IntelliJ 是否以管理员权限启动进程?

java - Intellij IDEA错误: Could not find or load main class test

java - 保存与 IntelliJ 插件模块关联的数据

java - Java for OS X 2013-004 如何影响(破坏)Swing 应用程序?

spring-boot - 使用 spring boot 连接被拒绝的 redis master slave

java - 使用 Java 从 SharePoint 列表中删除文件

java - 如何用spring-boot初始化ActiveMQ的SystemUsage?

java - 如何通过 Ant 将一个 jar 文件包含另一个 jar?

TCP 服务器上的 java.lang.ClassNotFoundException