is there any valid reason, all jersey resource classes are marked with @ManagedBean annotation. Already, the resource classes are marked with @Path and @Produces jaxrs annotations. is it not sufficient for the container to consider it as a jax-rs resource class?

有帮助吗?

解决方案

javax.annotation.ManagedBean is not a jax-rs annotation, and because of that, the container shouldn't assume anything about jax-rs when reading that annotation, so, yes, @Path and @Produces are enough for the container to consider it as a jax-rs resource. You can use @ManagedBean if you want additional services (non-jax-rs related) to be provided to your resources by the container, check the link.

其他提示

@ManagedBean annotation is required if you want to inject your EJBs in JAX-RS resources without using @Local annotations and interfaces on your EJBs.

Compare the following Jersey documentation topics:

  1. https://jersey.java.net/documentation/latest/deployment.html#deployment.javaee.managed
  2. https://jersey.java.net/documentation/latest/deployment.html#deployment.javaee.ejb

So you may choose what approach fits your needs well: either to use @Local interface + @Stateless EJB or to inject your @Stateless EJBs without @Local interface in your @ManagedBean annotated resource.

Also take a look at the official example: https://github.com/jersey/jersey/tree/master/examples/managed-beans-webapp

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top