出现意外错误(类型=错误请求,状态=400)

There was an unexpected error (type=Bad Request, status=400)

我在 Heroku 上托管了一个 Springboot 应用程序。构建和部署工作得很好。但是,每当我想访问该方法时,我都会看到此错误。 There was an unexpected error (type=Bad Request, status=400).如果我使用 loclhost,它在 Postman 上工作得很好,但在使用 Heroku 的应用程序时会抛出错误。

这是控制器的样子。我猜这就是问题所在。

.

..
@Slf4j
@RestController
@RequestMapping("/api/v1/")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping(value = "/addUser")
    public ResponseEntity<AddResponseDTO> addUser(@RequestBody AddUserDTO addUserDTO) throws ApplicationException {
        AddResponseDTO response = userService.saveUser(addUserDTO);
        return ResponseEntity.ok(response);
    }

}

您认为我可以做些什么来使 api 在 Heroku 上运行?

问题不在于 Springboot 控制器。如下所示检查您的 Heroku 配置。

=== <app_name>
Git Url:       git@heroku.com:<app_name>.git
Web Url:       https://<app_name>.herokuapp.com/

显然我试图访问一个 POST REQUEST 它肯定会抛出这样的错误。但是这里的错误是,我尝试使用本地 database.Thus,我使用 Mongo Atlas 创建了一个共享集群,更新了我的 application.properties 中的配置,我添加了变量配置到 Heroku,现在一切正常。