Scrivio Interview library
DesignPrincipal7 min read · updated 12 November 2026

Jakarta REST is gradually replacing its own @Context injection with CDI. As the person responsible for the Java platform standard, what does this history teach about framework-specific injection, and how should teams write resources today to stay portable?

JAX-RS invented @Context because CDI did not exist yet, and the result was two injection models with different rules for scopes, providers and proxies. Jakarta REST is now converging on CDI so that it works like the rest of Jakarta EE and like build-time containers such as Quarkus. Teams stay portable by using constructor or @Inject injection for services, receiving request objects as method parameters, keeping @Context in a few isolated places, preferring standard APIs over extensions, and treating injection changes as routine upgrade work.

Why this question is asked

A platform standard lasts for decades, and decisions made in its first version shape every application written against it. The story of @Context in JAX-RS is a clear example: a reasonable shortcut in 2008 became a second, slightly different injection system that every developer had to learn. An interviewer asking this at a principal or standards level wants to hear that we can read that history, explain the costs it created, and turn it into concrete advice for code written today. In this answer, we will recap how the two models came about, look at the problems that having both caused, explain why convergence on CDI makes sense, and then set out how we would write resources now so that the next change is cheap.

1A Quick Recap: Why JAX-RS Had Its Own Injection

JAX-RS 1.0 was finished in 2008. CDI, Contexts and Dependency Injection, the general injection standard for Java EE, arrived a year later in Java EE 6 and took several more releases to mature. JAX-RS needed a way to give resources the request URI, headers and security information, so it defined @Context, a small injection mechanism that only knows about the runtime's own types.

That was a sensible decision at the time. But once CDI existed, a JAX-RS application had two ways of getting objects: @Context for runtime types and @Inject for everything else. Each implementation also had its own internal container to support @Context; Jersey used HK2, for example. So three systems could be involved in creating one resource.

2What Two Injection Models Cost

The costs show up in the rules developers must remember. Which annotation works on which type? Can a provider, which is a singleton, receive a request object, and if so, is it the real object or a proxy? Is a resource managed by CDI, by the JAX-RS runtime, or by both, and what scope does it have? Can a CDI bean outside JAX-RS inject UriInfo? The answers differed between implementations and versions, which is the opposite of what a standard is for.

There were practical failures too. A field annotated with @Inject in a class the JAX-RS runtime created, but CDI did not manage, stayed null. Interceptors and CDI scopes did not apply to objects the JAX-RS runtime built on its own. Singleton providers received proxies that resolved through thread-bound state, which surprised people who passed them to another thread. Each of these is a small trap; together they make the platform harder to learn and harder to move between implementations.

Two models side by side
Question@Context (JAX-RS)@Inject (CDI)
What can be injected?a fixed set of runtime typesany bean, including our own
Who manages scope?the JAX-RS runtimethe CDI container
Request objects in singletonsthread-bound proxynormal-scoped proxy, same idea
Interceptors and decoratorsnot applied by @Context itselfapplied by CDI
Used outside REST codenoyes
Build-time wiringimplementation specificCDI Lite supports it
The same need served by two systems with different rules.

3Why Convergence on CDI Makes Sense

CDI is the injection model of the whole platform: Jakarta Persistence, Transactions, Security, Batch and MicroProfile all build on it. If REST uses it too, a developer learns one set of rules for scopes, qualifiers and proxies, and the same service can be injected into a resource, a message listener or a scheduled job without changes.

The second reason is build-time containers. Quarkus implements CDI Lite, a subset of CDI that can be resolved during the build, without runtime reflection or classpath scanning. That is what makes very fast startup and native images practical. A separate @Context mechanism has to be supported specially by such containers; if request objects are ordinary CDI beans, the same build-time machinery handles them. So the direction of Jakarta REST, making runtime objects injectable with @Inject and deprecating @Context in a future release, aligns the API with where the platform is going. The exact release in which each step lands has moved over time, so check your version of the specification and your implementation.

4How to Write Resources Today

The advice follows from the history. First, services, repositories and clients arrive through constructor injection, or @Inject where constructor injection is not supported. Those classes then do not depend on any REST annotation and do not care which container wires them. Second, request-specific objects are taken as method parameters, not fields. That works in both models, makes the dependency visible, and is safe in singletons because the runtime passes the value for exactly the current request. Third, where we need @Context, we keep it in a thin layer, the resource method signature or one small adapter, so that changing the annotation later touches a few lines.

Java
@Path("/orders")
@RequestScoped // a CDI-managed resource
public class OrderResource {
private final OrderService orders;
@Inject
public OrderResource(OrderService orders) { // services: constructor injection
this.orders = orders;
}
@GET @Path("/{id}")
public OrderView get(@PathParam("id") long id,
@Context UriInfo uri) { // request data: a parameter, easy to change later
return orders.view(id, uri.getAbsolutePath()); // OrderService never sees UriInfo
}
}

Notice that OrderService receives a plain URI, not the UriInfo. The service knows nothing about the REST layer, so it is testable with a simple value and portable across runtimes. Only one line would change when @Context gives way to another injection style.

5Standard APIs First, and Upgrades as Routine Work

Another lesson from the history is about extensions. Jersey and RESTEasy both offer useful features beyond the standard, such as their own injection binders, client extensions and configuration properties. When an extension and a standard API cost about the same, choose the standard one, because the extension ties the code to one implementation and its own deprecation schedule. When the extension is clearly better, use it, but wrap it in one place and record the decision so the next person knows where the dependency lives.

The last lesson is about time. The move from javax to jakarta packages, the move from @Context to CDI, and the removal of older features were all announced in advance. Teams that track each platform release, read the deprecation list, and fold small changes into their normal upgrade cycle never face a big rewrite. Teams that skip releases find several such changes at once. So I would make reading the deprecation notes part of every platform upgrade, add a build check or a static analysis rule that flags new @Context fields, and change existing code gradually as files are touched.

Step throughChoosing how a class gets an object
  1. Is it our own service or client?
    YesConstructor or @Inject injectionNoGo on
  2. Is it request data such as UriInfo?
    YesTake it as a method parameterNoGo on
  3. Is it a runtime object a provider needs?
    YesUse @Context in one small adapterNoPrefer a standard API
  4. Record it and revisit at each platform upgradedeprecations are announced ahead

4 steps in order. Play them, or step through them one at a time.

6Follow-up questions

Does this mean @Context will stop working soon?

Deprecation in a standard usually comes long before removal, and implementations keep supporting old features for compatibility for a long time. So existing code will not break overnight. The point is to stop adding new dependencies on it and to keep the existing ones easy to change. Check your version's specification and release notes for the exact status.

What about teams using Spring with JAX-RS?

The same advice holds. Spring can manage Jersey resources, and constructor injection of services works the same way under Spring as under CDI. Keeping request objects at method parameters and services free of REST types makes the code indifferent to whether Spring, CDI or the JAX-RS runtime wires it, which is exactly the portability we want.

How do build-time containers handle @Context today?

Quarkus with RESTEasy Reactive, for example, supports @Context and also lets request objects be injected with @Inject, resolving much of the wiring at build time. Other build-time frameworks have their own rules. Because these details change between releases, the safest path is code that uses standard method parameters and constructor injection, which every such container supports.

7Conclusion

In this answer, we saw that @Context came from a time before CDI, and that keeping two injection models created confusing rules about scopes, singletons, proxies and which objects can be injected where. Converging on CDI aligns Jakarta REST with the rest of the platform and with build-time containers such as Quarkus. For portable code today, we inject services through constructors, take request objects as method parameters, keep @Context in a thin isolated layer, prefer standard APIs over implementation extensions when the cost is similar, and handle injection changes as part of every regular upgrade.

What to say in the interviewAbout 90 seconds aloud

Open with

The lesson I take from @Context is that a framework-specific injection mechanism made sense when JAX-RS 1.0 shipped in 2008, because CDI did not exist yet, but once CDI arrived we had two models with different rules.

Then, if they want more

Developers had to know which annotation worked on which type, whether a singleton provider got a real object or a thread-bound proxy, and why an @Inject field stayed null in a class the REST runtime created. Implementations answered those questions differently, which is the opposite of what a standard is for.

Moving to CDI gives one set of rules across Jakarta EE and works with build-time containers like Quarkus, which resolve CDI Lite at build time for fast startup and native images. So for teams today, my advice is simple. Inject services through constructors, so service classes have no REST types at all.

Take request objects like UriInfo or SecurityContext as method parameters and pass plain values down to services. Keep any remaining @Context in a thin layer so the eventual change is a few lines. Prefer the standard API when an implementation extension costs about the same, and wrap extensions when we do use them.

And treat these deprecations as routine: read the notes for every platform release, add a check against new @Context fields, and migrate as we touch files rather than planning a big rewrite.

About this answer

Last updated
12 November 2026
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
Jakarta EE specifications
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 "Jakarta REST is gradually replacing its own @Context injection with CDI. As the person...": https://scrivio-interview-library.netlify.app/java/jax-rs/7722b6a9e4/