I’ve a class as shown below:
@Path("/myrequest")
@Scope("request")
@Component
public class MyRESTCode implements IServicedResource<T> {
@Inject
private IMyService serviceImpl;
@Override
public void setServiceImpl(IMyService impl) {
serviceImpl = impl;
}
}
@Path("/users")
@POST
@Consumes ({MediaType.APPLICATION_JSON})
@Produces ({MediaType.APPLICATION_JSON})
public Response mymethod(Object obj) throws Exception {
serviceImpl.callme(obj);
return Response.noContent().build();
}
Now, this callme method implementation exists in some other class (MyOtherClass.java).
Can any one tell me how mymethod invokes callme method in MyOtherClass.java, when /users POST request is made???
Also, who calls setServiceImpl method & how does it get set & when does it get called?
Thanks!
You must be having a spring applicationContext.xml which should look something like
In this xml, if you notice that base-package should be defined as a package where your controller class (in your case MyRESTCode.java) should be present. Spring will search for classes annotated as @Component and configures them at the path mentioned by @Path
When you hit the a post request with JSON in the body to the URL …./myrequest/users, the callme method gets invoked which in turn invokes your service method.
@Inject annotation tells spring that dependency of IMyService should be injected to serviceImpl variable through the setter method setServiceImpl.
Hope this helps.