简体   繁体   English

如何在JAX-RS REST Web服务中注入JMS资源?

[英]How do I inject a JMS resource in a JAX-RS REST Web Service?

Using GlassFish 3.1.2.1, I have configured a JMS connection factory and a queue, which can be injected in JavaServer Faces managed beans using the @Resource annotation. 使用GlassFish 3.1.2.1,我配置了一个JMS连接工厂和一个队列,可以使用@Resource批注将其注入JavaServer Faces托管bean中。

However when I try to use these JMS resources in a JAX-RS REST web service in the same project, the connectionFactory injection seems to be missing and there is a NullPointerException when the line is executed: 但是,当我尝试在同一项目的JAX-RS REST Web服务中使用这些JMS资源时,似乎缺少connectionFactory注入,并且在执行该行时会出现NullPointerException:

connection = exampleQueueFactory.createConnection();

The injection code is 注入代码是

@Resource(mappedName = "ExampleQueue")
private Queue exampleQueue;
@Resource(mappedName = "ExampleQueueFactory")
private ConnectionFactory exampleQueueFactory;

and as I successfully use the same injection in JSF managed beans I guess that the GlassFish server skips the JAX-RS classes when looking for injection points. 当我在JSF管理的bean中成功使用相同的注入时,我猜想GlassFish服务器在寻找注入点时会跳过JAX-RS类。 Is there additional configuration missing? 是否缺少其他配置?

Based on the answer to NullPointer in Glassfish when inject JMS @Resource I added a @javax.ejb.Stateless annotation and it works. 基于在注入JMS @Resource时Glassfish中NullPointer的答案,我添加了一个@javax.ejb.Stateless批注,并且该批注有效。

Follow-up question: is this the recommended way to enable injection of JMS resources in a JAX-RS resource class? 后续问题:这是在JAX-RS资源类中启用JMS资源注入的推荐方法吗?

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

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