【问题标题】:There was an unexpected error (type=Bad Request, status=400)出现意外错误(类型=错误请求,状态=400)
【发布时间】:2021-09-19 10:19:35
【问题描述】:

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

这是控制器的外观。我猜这就是问题所在。

.

..
@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 上工作?

【问题讨论】:

    标签: java spring-boot heroku


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 点击以下链接
      • 您可能正在访问 git.heroku.com/your-app-name.git 而不是 your-app-name.herokuapp.com
      • 点击上面的链接你会得到一些想法
      • 这根本不是问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 2017-09-07
      • 2015-04-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2015-06-12
      相关资源
      最近更新 更多