简体   繁体   中英

Managed Bean for jersey resource classes

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM