弹簧启动后休息调用"Required request body is missing"



我有一个简单的角度学校项目,带有弹簧启动后端。每当我尝试通过休息调用从前端向后端发送内容时,都会收到"缺少必需的请求正文">

前端代码

export class TestController {
private usersUrl: string;
private authorizationMessage: AuthorizationMessage;
constructor(
private httpClient: HttpClient
) {
this.usersUrl = 'http://localhost:8080/fraud/';
}
public testDatabase() {
this.authorizationMessage = new AuthorizationMessage();
this.authorizationMessage.bitMap = 1;
this.authorizationMessage.carAcceptorName = 'mitchel';
this.authorizationMessage.cardAcceptorId = 'cardAcceptorId';
this.authorizationMessage.cardAcceptorTerminalId = 8762344;
this.authorizationMessage.cardSequenceNumber = 12;
this.authorizationMessage.checkInformation = 'check info test';
this.authorizationMessage.messageTypeIdentifier = 3;
this.authorizationMessage.posDataCode = 'posDataCode';
this.authorizationMessage.primaryAccountNumber = 29485819;
this.authorizationMessage.processingCode = 90;
this.authorizationMessage.responseCode = 0;
this.authorizationMessage.systemTraceAuditNumber = 65;
this.authorizationMessage.transactionAmount = 45;
this.authorizationMessage.transmissionDateAndTime = new Date();
console.log(this.authorizationMessage);
return this.httpClient.post(this.usersUrl + 'authorizeTransaction', this.authorizationMessage).subscribe();
}
}

前端的授权消息类

export class AuthorizationMessage {
messageTypeIdentifier: number;
bitMap: number;
processingCode: number;
transactionAmount: number;
transmissionDateAndTime: Date;
systemTraceAuditNumber: number;
responseCode: number;
cardAcceptorId: string;
posDataCode: string;
cardAcceptorTerminalId: number;
carAcceptorName: string;
primaryAccountNumber: number;
checkInformation: string;
cardSequenceNumber: number;
}

后端代码

@RestController
@RequestMapping(value= "/fraud", produces = MediaType.APPLICATION_JSON_VALUE)
@Slf4j
public class FraudController {
private RuleEngine ruleEngine;
@Autowired
public FraudController(RuleEngine ruleEngine){
this.ruleEngine = ruleEngine;
}
@PostMapping(value = "/authorizeTransaction", consumes = MediaType.APPLICATION_JSON_VALUE)
public void authorizeTransaction(@RequestBody @Valid AuthorizationMessage authorizationMessage){
TransactionContext transactionContext = getTransactionContext(authorizationMessage);
transactionContext = ruleEngine.evaluateTransaction(transactionContext);
updateTransactionHistory(authorizationMessage);
}
}

授权后端中的消息

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AuthorizationMessage implements Serializable {
private Integer messageTypeIdentifier;
private Integer bitMap;
private Integer processingCode;
private Long transactionAmount;
private LocalDateTime transmissionDateAndTime;
private Integer systemTraceAuditNumber;
private Integer responseCode;
private String cardAcceptorId;
private String posDataCode;
private Integer cardAcceptorTerminalId;
private String carAcceptorName;
private Long primaryAccountNumber;
private String checkInformation;
private Integer cardSequenceNumber;
}

确切的输出是

2019-12-30 15:09:18.341  WARN 89353 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void nl.han.ica.oose.s1920.g9.frauddetection.controllers.FraudController.authorizeTransaction(nl.han.ica.oose.s1920.g9.frauddetection.core.authorizationmessage.AuthorizationMessage)]

我不知道为什么找不到请求正文。也许我忘记了某些东西,某处的某种设置或配置,或者序列化不像我期望的那样工作......希望有人能帮忙。

已解决:

模块缺少用于验证 cors 的 WebConfig。将其添加到项目中并按预期工作。

相关内容

最新更新