简体   繁体   English

球衣资源类的托管Bean

[英]Managed Bean for jersey resource classes

is there any valid reason, all jersey resource classes are marked with @ManagedBean annotation. 是否有任何正当理由,所有球衣资源类均标有@ManagedBean批注。 Already, the resource classes are marked with @Path and @Produces jaxrs annotations. 资源类已经用@Path和@Produces jaxrs批注标记。 is it not sufficient for the container to consider it as a jax-rs resource class? 容器将其视为jax-rs资源类还不够吗?

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. javax.annotation.ManagedBean不是jax-rs批注,因此,在读取该批注时,容器不应假定有关jax-rs的任何内容,因此,@ @Path@Produces足以让容器考虑作为jax-rs资源。 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 . 如果您希望容器向您的资源提供其他服务(与非jax-rs相关),则可以使用@ManagedBean,请检查链接

@ManagedBean annotation is required if you want to inject your EJBs in JAX-RS resources without using @Local annotations and interfaces on your EJBs. 如果要在不使用EJB上的@Local注释和接口的情况下将EJB注入JAX-RS资源中,则需要@ManagedBean注释。

Compare the following Jersey documentation topics: 比较以下泽西岛文档主题:

  1. https://jersey.java.net/documentation/latest/deployment.html#deployment.javaee.managed https://jersey.java.net/documentation/latest/deployment.html#deployment.javaee.managed
  2. https://jersey.java.net/documentation/latest/deployment.html#deployment.javaee.ejb 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. 因此,您可以选择最适合自己需求的方法:使用@Local接口+ @Stateless EJB或在@ManagedBean注释的资源中注入不带@Local接口的@Stateless EJB。

Also take a look at the official example: https://github.com/jersey/jersey/tree/master/examples/managed-beans-webapp 还可以看一下官方示例: https : //github.com/jersey/jersey/tree/master/examples/managed-beans-webapp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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