Quick revision
The short answer
A post-processor is attractive because it reaches every matching client bean without any change in the applications. But it must not depend on regular beans such as the MeterRegistry or the tracer, or it forces them to be created early and they lose their own post-processing, and wrapping a client in a proxy changes its type, which breaks injection by concrete class. I would prefer the documented hooks: customiser beans such as RestClientCustomizer, and the Micrometer observation support that Spring's HTTP clients already have built in.
What to remember
In this answer, we evaluated a shared-starter post-processor that wraps HTTP client beans. Its appeal is zero application changes, but it must not depend on regular beans without causing early initialisation, and wrapping changes bean types and misses clients built from builders. Spring's HTTP clients already support Micrometer observations, and Spring Boot's builder customisers let a starter add company-wide behaviour safely. So we recommended customisers and observation conventions, with detection rather than wrapping for clients built outside the builder.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A post-processor is attractive because it reaches every matching client bean without any change in the applications. But it must not depend on regular beans such as the MeterRegistry or the tracer, or it forces them to be created early and they lose their own post-processing, and wrapping a client in a proxy changes its type, which breaks injection by concrete class. I would prefer the documented hooks: customiser beans such as RestClientCustomizer, and the Micrometer observation support that Spring's HTTP clients already have built in.
Why this question is asked
Platform teams want every service to emit the same HTTP client metrics and traces, and they want it without asking fifty teams to change code. A BeanPostProcessor in the shared starter looks like the perfect tool, because it sees every bean. Interviewers ask this design question at the fifteen-year level to see whether we can weigh that convenience against the subtle lifecycle problems it brings, and whether we know the extension points Spring and Spring Boot already offer for exactly this. In this answer, we will sketch the proposed design, look at the two serious problems with it, then at the built-in alternatives, and finish with a recommendation and what the starter should still contain.
1The Proposed Design and Why It Is Attractive
The idea is a post-processor that looks at every bean after initialisation and, when the bean is an HTTP client, returns a proxy that times each call, records a metric and starts a tracing span. Because Spring calls every BeanPostProcessor for every bean, the starter would instrument all clients automatically, including ones the platform team has never seen.
The appeal is real. Zero code changes in applications, one place to maintain, and a consistent metric name across the company. The question is what it costs.
2Problem 1: Dependencies on Regular Beans
Spring creates and registers all post-processors before it creates ordinary beans, because it needs them to process those beans. If our post-processor takes a MeterRegistry and a Tracer in its constructor, Spring has to create those two beans, and everything they depend on, during post-processor registration. The post-processors registered after that moment never see them, and Spring logs that these beans are 'not eligible for getting processed by all BeanPostProcessors'.
The consequences are subtle and can be far from our starter. The meter registry may miss customisation that other post-processors apply, an exporter bean created along the way may lack its proxies, and the order in which this happens differs between applications, depending on which other starters they use. A shared starter is the worst place for this, because the platform team cannot test every combination.
It can be reduced: declare the post-processor with a static @Bean method and inject ObjectProvider<MeterRegistry> so the registry is looked up on the first call instead of at construction. That removes the early creation, but it does not solve the second problem.
3Problem 2: Wrapping Changes Bean Types
A proxy built by ProxyFactory is either a JDK dynamic proxy, which implements only interfaces, or a CGLIB subclass. Both cause trouble for HTTP clients. RestTemplate is a class; a JDK proxy for it only implements RestOperations, so a service that injects RestTemplate fails at startup with a bean type mismatch. A CGLIB subclass keeps the type but requires the class to be non-final and creates an extra object per client with the constructor rules CGLIB imposes. RestClient and WebClient are interfaces, so a JDK proxy keeps the interface type, but their builders, which applications often inject and use to build clients in code, would not be instrumented at all.
There are more hidden effects. Debugging shows generated classes, and a second proxy from an application aspect makes the order of proxies decide what is measured. Most importantly, a proxy around the client sees method calls such as get() or exchange(), not HTTP requests, so it cannot easily read the URI template, status code or headers that good metrics and traces need.
| Bean type | Proxy kind | Effect |
|---|---|---|
RestTemplate (class) | JDK proxy of RestOperations | injection of RestTemplate fails |
RestTemplate (class) | CGLIB subclass | works, but extra subclass and ordering issues |
RestClient (interface) | JDK proxy | type kept; clients built in code not covered |
RestClient.Builder | not wrapped | most clients are built from it: no metrics |
| Third-party client (final class) | none possible | proxy creation fails |
4The Built-in Alternatives
Spring and Spring Boot already solve this problem at the right level. First, Spring Framework 6's HTTP clients support Micrometer Observation directly: RestClient, RestTemplate and WebClient accept an ObservationRegistry and record an observation per HTTP request, which Micrometer turns into an http.client.requests timer and, with a tracing bridge, a span with propagated headers. Second, Spring Boot auto-configures the builders, RestClient.Builder, RestTemplateBuilder and WebClient.Builder, with that observation support already applied, and lets any bean of a customiser type adjust them.
Notice the differences from the wrapping design. The customiser is an ordinary bean, created at the normal time, so it has no lifecycle traps. It works at the HTTP request level, so it sees the URI template and status code. And it applies to clients built in code, which is the usual case, because those are built from the builder the customiser has already configured. The exact customiser and observation class names are stable in recent Spring Boot versions, but check your version before relying on a particular one.
5Recommendation and What the Starter Should Contain
I would reject the wrapping post-processor and design the starter around documented customisation hooks. It would contain customisers for the builders (RestClientCustomizer, WebClientCustomizer and RestTemplateCustomizer), observation filters or conventions for company-wide tags, and configuration for exporters. For clients that are not Spring's, such as an SDK built on OkHttp or Apache HttpClient, it would offer their own interceptor or customiser hooks with a small helper, rather than a proxy.
What about clients that applications create with new instead of from the builder? A post-processor can still help there, but only to report, not to wrap: it can log a warning at startup listing client beans that have no observation registry configured, or the platform can add an ArchUnit rule that forbids new RestTemplate() in application code. Detection plus a documented path is far safer than silent replacement.
- Is there a documented hook (customiser, observation)?YesUse it in the auto-configurationNoLook for the client library's own interceptor API
- Does the library offer interceptors?YesProvide a helper that registers oursNoConsider a proxy as a last resort
- Detect clients built without the builderstartup warning or ArchUnit rule
- Document the supported path for teams
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Is a BeanPostProcessor ever the right tool in a shared starter?
Yes, when no documented hook exists and the change cannot alter the bean's type, for example registering an existing bean with a registry, or adding an interceptor to an object that exposes a setter for it. Even then it should be static, depend on nothing but ObjectProvider handles, and be easy to switch off with a property.
How would you roll out the change without breaking teams?
Ship the customisers in a minor starter version, verify in two or three pilot services that the metric names and tags match the dashboards, then announce the supported builder-based pattern. Services that construct clients manually get a startup warning first and an ArchUnit rule later.
What about high-cardinality tags?
Observation filters must only add low-cardinality values, such as team or region. Adding user IDs or full URLs would create a new time series per value and overload the metrics backend, which is another reason to use the URI template the built-in support already provides.
7Conclusion
In this answer, we evaluated a shared-starter post-processor that wraps HTTP client beans. Its appeal is zero application changes, but it must not depend on regular beans without causing early initialisation, and wrapping changes bean types and misses clients built from builders. Spring's HTTP clients already support Micrometer observations, and Spring Boot's builder customisers let a starter add company-wide behaviour safely. So we recommended customisers and observation conventions, with detection rather than wrapping for clients built outside the builder.
Open with
I see why the post-processor is attractive: it reaches every client bean with no change in any application. But I would not build it that way, for two reasons.
Then, if they want more
First, post-processors are created before ordinary beans, so if it injects the MeterRegistry or the Tracer, those beans are created early, miss the post-processors registered later, and we get 'not eligible for getting processed by all BeanPostProcessors' problems that differ from service to service.
We could reduce that with a static @Bean and ObjectProvider, but the second problem remains: a proxy changes the bean type. A JDK proxy of RestTemplate only implements RestOperations, so anything injecting RestTemplate breaks, and most clients are built in code from RestClient.Builder, which the wrapper never sees. A method-level proxy also cannot read the URI template or status code.
Spring already has better hooks. The HTTP clients in Spring Framework 6 have Micrometer observation built in, and Spring Boot configures the builders with it and applies customiser beans like RestClientCustomizer.
So the starter should contain customisers and observation filters for company tags, helpers for third-party clients' own interceptor APIs, and only a startup warning or an ArchUnit rule for clients built outside the builder.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A platform team wants a BeanPostProcessor in the shared starter that wraps every HTTP...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/67f4580cdd/