【发布时间】:2018-07-20 04:33:44
【问题描述】:
我用 Spring 5 响应式编写了一个自定义异常
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class AddressNotFoundException extends RuntimeException{
public AddressNotFoundException(String message) {
super(message);
}
我在服务中称它为:
@Override
public Mono<Address> getById(String id) {
Address addressFound=repository.findById(id).block();
if(Objects.equals(addressFound, null))
throw new AddressNotFoundException("Address #"+id+" not found");
return Mono.just
(addressFound);
}
但是当我到达此页面时,会引发异常,但不是 404,而是空指针异常和错误 500 页面,但消息正确?
永远不会抛出 AddressNotFound,只有 Nullpointer 异常但带有我的自定义消息??? 你能帮帮我吗?
这是我的控制器:
@GetMapping("/address/{id}")
public Mono<Address> byId(@PathVariable String id) {
return addressService.getById(id);
}
谢谢
【问题讨论】:
标签: java spring exception-handling nullpointerexception