Cherry
Cherry

Reputation: 33534

Bean creation intercepter

Let asy that there are several org.springframework.web.reactive.function.client.WebClient classes in the application which creatred like that:

@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.

It is needed to add filters for all create WebClients. Some thing like that:

public WebClient intercepter(WebClient webClient) {
    return webClient.mutate().filter(setupFilter());
}

Can this be possible with spring 5?

Upvotes: 0

Views: 98

Answers (1)

Azee
Azee

Reputation: 1829

I assume you don't have permissions to modify the code of beans provided?

In that case you can implement a BeanPostProcessor - detect WebClient implementations (or methods by return type) and return updated value in each method.

Alternatively you can replace the real implementation of WebClient with the decorator in your post-processor.

Here is the example of how to implement a processor. In this case Locking operations are being injected into original methods.

Don't forget to include your post processor to the context

Upvotes: 1

Related Questions