I have simple restful WS
@Path("basic")
public class ServiceRS
{
private IServiceJAX service;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String find(@FormParam("searchRequest") final String searchRequest)
{
//...
final List<Info> response = service.find(search);
//...
}
}
Where IServiceJAX
is @Local
interface of jax-webservice.
Can I inject IServiceJAX
to ServiceRS
using annotation?
I don't want use JNDI lookup...
Sure, you can. Although I suppose there are other ways, I have successfully run a simple test project with a
@Stateless
@WebService
,@Local
implementation of aninterface
, injected through@EJB
annotation into a@Stateless
RESTFul web service annotated with@Path
.This is not properly a CDI injection as you have demanded, but it works nicely and probably fits your needs anyway.
IServiceJAX class:
IServiceJAXImpl class:
ServiceRS class:
UPDATE
If you prefer CDI injection, you can keep the above code and simply remove
@Local
and@Stateless
annotations fromIServiceJAXImpl
. You can inject an instance of this class using:instead of