我使用Spring-webflux创建RouterFunction和Handler。我有 @Aspect for My handler函数如下所示,将serverRequest正文和ServerResponse正文存储在database.But当试图获取Object时,我的请求被挂起。是否有任何示例代码来实现此功能。
@Around("@annotation(Log")
public Object log(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
Object o = proceedingJoinPoint.proceed();
ServerRequest serverRequest = ServerRequest.class.cast(proceedingJoinPoint.getArgs()[0]);
Mono<Customer> customerMono = serverRequest.bodyToMono(Customer.class);
Customer customer = customerMono.block() //Request Hanged here
log.info("customer" + customer);
return o;
}
答案 0 :(得分:-1)
block()
是一个阻止调用,因此当你调用它时它会挂起。
要打印Mono<Customer> customer
内的客户数据,请尝试以下操作:
customerMono.flatMap(customer -> System.out.println(customer)); // longhand form
customerMono.flatMap(System.out::println); // shorthand form of the above