0
即時通訊目前有注射@Stateless
-ejb到我RestEasy的實現web服務的一個問題:進樣EJB到Web服務RestEasy的
資源:
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
代替 - 也不起作用。