1

Consider the following Spring MVC annotation:

@RequestMapping(value="content", 
                method=RequestMethod.GET, 
                produces = "application/json; charset=UTF-8")

The equivalent in JAX-RS/Jersey is:

@GET
@Path("content")
@Produces(MediaType.APPLICATION_JSON)

I am looking for the equivalent Spring MVC annotation for the following JAX-RS/Jersey annotations:

  • @Context
  • @FormParm
  • @BeanParam
cassiomolin
  • 124,154
  • 35
  • 280
  • 359
Raj Bhatia
  • 1,049
  • 4
  • 18
  • 37

1 Answers1

5

@FormParam

In JAX-RS, @FormParam binds the value(s) of a form parameter contained within a request entity body to a resource method parameter.

There's no direct equivalent to @FormParam in Spring MVC. The closest you will find is @RequestParam:

@RequestParam("foo") String foo

And you also can get the parameter from the request:

String foo = request.getParameter("foo");

@BeanParam

In JAX-RS, @BeanParam can be used to inject custom JAX-RS parameter aggregator value object into a resource class field, property or resource method parameter.

I'm not aware of any annotation that gives you a similar feature but according to this answer, you can create a class with field names that match your request parameters and add it as a method argument in your request handler method.

@Context

In JAX-RS, @Context is used to inject JAX-RS contextual information into a class field, bean property or method parameter. So you won't find a direct equivalent to @Context in Spring MVC either.

However Spring MVC has a predefined set of types that can automagically injected in method arguments.

And you also can use @Autowired to inject some request/response contextual information in your class fields:

@Autowired
HttpServletRequest request;
cassiomolin
  • 124,154
  • 35
  • 280
  • 359