gpt4 book ai didi

java - Wildfly 9 JMS 注入(inject)未发生

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:50 25 4
gpt4 key购买 nike

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

@ApplicationScoped
public class JMSEventPublisher implements IEventPublisherClient {

@Inject
private JMSContext context;

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

我尝试过使用 @Stateless 而不是 @ApplicationScoped,并且尝试使用 lookup 而不是 mappedName,但 context 和syncQueue 字段从未被注入(inject)(因此当我尝试发送 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

知道为什么这次注入(inject)没有发生吗?

最佳答案

感谢@John Ament,他提出了正确的问题。我发现在我的工厂类中,引用是由 new 创建的,因此 WELD 没有进行注入(inject)。问题已解决。

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

关于java - Wildfly 9 JMS 注入(inject)未发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33800602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com