Home > Net >  Jax Rs to Rest Controller
Jax Rs to Rest Controller

Time:11-10

I have a rest end point written using JAX-RS

 import javax.ws.rs.core.Context

    @POST
    public Response something(@RequestBody MyOrderObject obj1,@Context MyObject obj2) {
    
    }

I want to write the above rest end point using Spring Rest.What should I replace the @Context in Spring Boot ?

@RestController
     class MyController
     {
    @POST
    public @ResponseBody something(@RequestBody MyOrderObject obj1) {

    }
    }

CodePudding user response:

The @Context is Dependency Injection featured by JAX-RS. See also: https://dzone.com/articles/jax-rs-what-is-context

In your case just inject MyObject object2 into your class as an attribue via @Autowired so you can use it later:

class MyController {

  private final MyObject object2;

  @Autowired
  public MyController(MyObject object2) {
    this.object2 = object2;
  }
  ...
}

  • Related