Wildfly 9 JMS 注入没有发生

Wildfly 9 JMS injection not happening

以下 class 在 JBoss 9.02-final 中部署,但注入的字段为空:

@ApplicationScoped
public class JMSEventPublisher implements IEventPublisherClient {

    @Inject
    private JMSContext context;

    @Resource (mappedName = "java:/jms/queue/Events")
    private Queue syncQueue;

我试过使用 @Stateless 而不是 @ApplicationScoped,我也试过使用 lookup 而不是 mappedName,但是上下文和同步队列字段永远不会注入(因此当我尝试发送 JMS 消息时出现空指针异常)。

启动 war 时,JBoss 日志中没有错误消息。在 JBoss 启动时,这是与 JMS 相关的输出,我们可以在其中看到命名队列似乎已启动,没有任何错误消息:

10:41:59,972 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 64) HQ221001: HornetQ Server version 2.4.7.Final (2.4.7.Final, 12
4) [34da3fdf-8dba-11e5-9213-51bb5b0e6fe5] 
10:42:00,399 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 64) WFLYMSG0002: Bound messaging object to jndi name java:jboss/ex
ported/jms/RemoteConnectionFactory
10:42:00,459 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 68) HQ221003: trying to deploy queue jms.queue.DLQ
10:42:00,471 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 69) WFLYMSG0002: Bound messaging object to jndi name java:/Connect
ionFactory
10:42:00,472 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 67) HQ221003: trying to deploy queue jms.queue.Events
10:42:00,476 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 66) HQ221003: trying to deploy queue jms.queue.ExpiryQueue
10:42:00,550 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-3) WFLYJCA0007: Registered connection factory java:/JmsXA
10:42:00,633 INFO  [org.hornetq.ra] (MSC service thread 1-3) HornetQ resource adaptor started
10:42:00,642 INFO  [org.jboss.as.connector.services.resourceadapters.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service 
thread 1-3) IJ020002: Deployed: file://RaActivatorhornetq-ra
10:42:00,647 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-3) WFLYJCA0002: Bound JCA ConnectionFactory [java:/JmsXA]
10:42:00,648 INFO  [org.jboss.as.messaging] (MSC service thread 1-3) WFLYMSG0002: Bound messaging object to jndi name java:jboss/DefaultJMSC
onnectionFactory

知道为什么没有发生这种注入吗?

感谢@John Ament,他提出了正确的问题。我发现在我的工厂class中引用是由一个new创建的,所以WELD没有做注入。问题已解决。

我删除了 new JMSEventPublisher() 并在工厂 class 的字段上添加了 @Inject(顺便说一句,我的 JMSEventPublisher 工作版本使用 lookup 而不是 mappedName 用于 syncQueue 的资源查找)。