Take the 2-minute tour ×

In the Rest API design, I am wondering what the exact purpose of the context annotation?

private HttpServletRequest request;

 public void setRequest(final HttpServletRequest req) {
        request = req;
share|improve this question

2 Answers 2

up vote 4 down vote accepted

The purpose is to indicate that the request property should be set from the context.

@Context is used to inject various HTTP-ish contextual data, from here:

In general @Context can be used to obtain contextual Java types related to the request or response.

API docs (Not horribly useful IMO. Or, perhaps more accurately, horribly-useful.)

share|improve this answer

This annotation is used to inject information into a class field, bean property or method parameter.

JAX-RS @Context to get the ServletContext, and WebApplicationContextUtils to get the Spring application context, with this Spring application context, you are able to access and get beans from Spring container

share|improve this answer

Your Answer


