【发布时间】:2015-06-29 01:45:47
【问题描述】:
我目前在将@Stateless-EJB 注入到我的 RESTeasy 实现的 web 服务中时遇到问题:
资源:
import javax.ejb.EJB;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/rest/events")
public class EventResource
{
@EJB
EventService eventService;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAllEvents()
{
System.out.println(eventService);
return Response.ok().build();
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response getEventById(@PathParam("id") String id)
{
System.out.println(id);
int intId = Integer.parseInt(id);
Event e = eventService.getById(intId);
System.out.println(e);
return Response.ok(e).build();
}
服务:
@Stateless
public class EventService
{
...
}
应用:
public class SalomeApplication extends Application
{
private Set<Object> singletons = new HashSet();
private Set<Class<?>> empty = new HashSet();
public SalomeApplication()
{
this.singletons.add(new EventResource());
}
public Set<Class<?>> getClasses()
{
return this.empty;
}
public Set<Object> getSingletons()
{
return this.singletons;
}
}
我正在使用org.jboss.resteasy:resteasy-jaxrs:3.0.11.Final、Wildfly 和应用程序服务器。我也尝试使用 Inject 和 RequestScoped 代替 - 也不起作用。
【问题讨论】: