Spring boot Spring启动应用程序不允许get请求

Spring boot Spring启动应用程序不允许get请求,spring-boot,Spring Boot,我按照这里的教程创建了一个springboot-elastic搜索应用程序。 我能够成功地完成POST和PUT方法,但GET请求失败 我用邮递员 GET失败,出现以下异常 { "timestamp": "2019-03-09T10:45:18.496+0000", "status": 405, "error": "Method Not Allowed", "message": "Request method 'GET' not supported", "p

我按照这里的教程创建了一个springboot-elastic搜索应用程序。 我能够成功地完成POST和PUT方法,但GET请求失败 我用邮递员

GET失败,出现以下异常

{
    "timestamp": "2019-03-09T10:45:18.496+0000",
    "status": 405,
    "error": "Method Not Allowed",
    "message": "Request method 'GET' not supported",
    "path": "/api/v1/profiles/464d06e8-ef57-49f3-ac17-bd51ba7786e2"
}
但是我在控制器中正确地添加了相应的get方法

@RestController("/api/v1/profiles")
public class ProfileController {

    private ProfileService service;

    @Autowired
    public ProfileController(ProfileService service) {

        this.service = service;
    }

    @PostMapping
    public ResponseEntity createProfile(
        @RequestBody ProfileDocument document) throws Exception {

        return 
            new ResponseEntity(service.createProfile(document), HttpStatus.CREATED);
    }

    @GetMapping("/{id}")
    public ProfileDocument findById(@PathVariable String id) throws Exception {

        return service.findById(id);
    }
}
在回复中,我可以看到它只允许PUT和POST。但是我在服务器中找不到任何配置文件来显式添加除控制器之外的http方法

@RestController("/api/v1/profiles")
public class ProfileController {

    private ProfileService service;

    @Autowired
    public ProfileController(ProfileService service) {

        this.service = service;
    }

    @PostMapping
    public ResponseEntity createProfile(
        @RequestBody ProfileDocument document) throws Exception {

        return 
            new ResponseEntity(service.createProfile(document), HttpStatus.CREATED);
    }

    @GetMapping("/{id}")
    public ProfileDocument findById(@PathVariable String id) throws Exception {

        return service.findById(id);
    }
}

有人能帮忙吗?

我看到的控制器问题是,控制器类级别没有@RequestMapping/api/v1/profiles。应该是

@RestController
@RequestMapping("/api/v1/profiles")
无法在@RestController的值字段中指定请求路径。这意味着根据javadocs

该值可能表示对逻辑组件名称的建议,以 在自动检测到组件的情况下,将转换为SpringBean


希望这能有所帮助。

我看到的控制器问题是,控制器类级别没有@RequestMapping/api/v1/profiles。应该是

@RestController
@RequestMapping("/api/v1/profiles")
无法在@RestController的值字段中指定请求路径。这意味着根据javadocs

该值可能表示对逻辑组件名称的建议,以 在自动检测到组件的情况下,将转换为SpringBean


希望这有帮助。

只是好奇而已。为什么发和放的工作,但没有得到?这对我来说也是一个谜。我不知道POST&PUT是如何工作的。甚至在Spring文档中也没有提到这样的东西。它只是说这段代码使用了Spring4新的@RestController注释,该注释将类标记为控制器,其中每个方法都返回一个域对象而不是视图。为什么发和放的工作,但没有得到?这对我来说也是一个谜。我不知道POST&PUT是如何工作的。甚至在Spring文档中也没有提到这样的东西。它只是说这段代码使用了Spring4新的@RestController注释,该注释将类标记为控制器,其中每个方法都返回一个域对象而不是视图。