我有一个抽象类AbstractResourse,带有createHuman()方法
@AllArgsConstructor
public abstract class AbstractResource {
........
@PostMapping
public humanDto createHuman() {
return service.createHuman();
}
.......
在AdminResource类中,我重写了createHuman()方法:
@RestController
@RequestMapping(value = "/admin/human", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdminResource extends AbstractResource{
@Override
public humanDto createHuman(humanDto entity) {
throw new NotImplementedException();
}
我有NotImplementedException类:
@ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED,
reason = "Method not allowed")
public class NotImplementedException extends RuntimeException {
public NotImplementedException (String s) {
super(s);
}
public NotImplementedException () {
}
}
当我发出POST请求时,我想获得HttpStatus的异常。但是我得到了Swagger的回复
Code: 500
Error:Response body
{
"error": {
"type": "EXCEPTION",
"code": "EXCEPTION",
"message": "NotImplementedException: Method not allowed",
"businessException": true
},
"status": "ERROR",
"correct": false
}
我使用本文Baeldung
我需要你的帮助。谢谢。