假设应用程序中有几个org.springframework.web.reactive.function.client.WebClient
类,它们是这样创建的:
@Bean
@Qualifier("one")
public WebClient one() {
return WebClient.builder().baseUrl("someUrl").build();
}
@Bean
@Qualifier("two")
public WebClient two() {
return WebClient.builder().baseUrl("someUrl").build();
}
//etc.
需要为所有的create WebClient
添加过滤器。类似这样的事情:
public WebClient intercepter(WebClient webClient) {
return webClient.mutate().filter(setupFilter());
}
这在spring 5中是可能的吗?
发布于 2018-11-22 13:57:24
我假设您没有权限修改所提供的bean的代码?
在这种情况下,您可以实现一个BeanPostProcessor检测的WebClient实现(或按返回类型的方法),并在每个方法中返回更新值。
或者,您可以使用后处理器中的装饰器替换WebClient的实际实现。
如何实现处理器的Here is the example。在这种情况下,锁定操作被注入到原始方法中。
https://stackoverflow.com/questions/53423918
复制相似问题