首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Bean创建拦截器

Bean创建拦截器
EN

Stack Overflow用户
提问于 2018-11-22 12:30:25
回答 1查看 38关注 0票数 0

假设应用程序中有几个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中是可能的吗?

EN

回答 1

Stack Overflow用户

发布于 2018-11-22 13:57:24

我假设您没有权限修改所提供的bean的代码?

在这种情况下,您可以实现一个BeanPostProcessor检测的WebClient实现(或按返回类型的方法),并在每个方法中返回更新值。

或者,您可以使用后处理器中的装饰器替换WebClient的实际实现。

如何实现处理器的Here is the example。在这种情况下,锁定操作被注入到原始方法中。

别忘了include your post processor to the context

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53423918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档