【发布时间】:2019-08-03 15:22:02
【问题描述】:
我正在编写一个 Spring Boot 应用程序。我的控制器有 2 个自定义请求标头。我正在执行一些测试,只是发现我的应用程序在标题不存在时返回“404”。
但是,我希望这会导致“400”错误?
谁能详细说明为什么会这样?以及我应该如何正确处理它?就像告诉服务的消费者一样,标头丢失了?
@RestController("fundsConfirmationController")
@RequestMapping(
value="/accounts/{accountId}/funds-confirmations",
headers = {"X-CAF-MSGID", "X-AccessToken"}
)
public class FundsConfirmationController implements FundsConfirmationControllerI{
private FundsConfirmationServiceI fundsConfirmationService;
@Autowired
public FundsConfirmationController(FundsConfirmationServiceI fundsConfirmationService){
this.fundsConfirmationService = fundsConfirmationService;
}
@GetMapping(
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<?> fundsConfirmation(@RequestHeader(value="X-CAF-MSGID") String messageId,
@RequestHeader(value="X-AccessToken") String accessToken,
FundsConfirmationRequest requestParams) { ... }
【问题讨论】:
标签: java spring-boot spring-mvc error-handling controller