首页 > 解决方案 > 调用 REST API 时 GCP 中的异常

问题描述

我是 GCP 的新手,并部署了一个带有 mysql db 连接的示例 spring boot 应用程序。在调用休息 API 时遇到异常。相同的原因可能是什么。

2021-06-26T05:56:35.029691281Zcom.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
Info
2021-06-26T05:56:35.029699031Z{
Info
2021-06-26T05:56:35.029705107Z "code" : 403,
Info
2021-06-26T05:56:35.029711431Z "errors" : [ {
2021-06-26T05:56:35.029717697Z "domain" : "global",
Info
2021-06-26T05:56:35.029723141Z "message" : "Insufficient Permission",
Info
2021-06-26T05:56:35.029729203Z "reason" : "insufficientPermissions"
Info
2021-06-26T05:56:35.029735192Z } ],
Info
2021-06-26T05:56:35.029741632Z "message" : "Request had insufficient authentication scopes.",
Info
2021-06-26T05:56:35.029747360Z "status" : "PERMISSION_DENIED"
Info
2021-06-26T05:56:35.029753095Z}

以下端点工作正常

@SpringBootApplication
public class EmployeeJdbcApplication {

    @RequestMapping("/")
    String home() {
        return "This is sample jdbc mysql connection app.....";
    }
    
    public static void main(String[] args) {
        SpringApplication.run(EmployeeJdbcApplication.class, args);
    }

}

获取以下端点的异常

@RestController
public class EmployeeController {

    @Autowired
    EmployeeService empService;

    @RequestMapping(value = "/employees", method = RequestMethod.GET)
    public List<Employee> getEmployees() {

        return empService.getAllEmployees();

    }
    
    @RequestMapping(value = "/insertemployee", method = RequestMethod.POST)
    public void insertEmployee(@RequestBody Employee employee) {
        empService.insertEmployee(employee);
    }
}

标签: spring-bootgoogle-cloud-platformspring-cloud-gcp

解决方案


推荐阅读