You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Wildfly 12中@Resource注入需加"java:/"前缀?Weblogic JMS迁移问题

Weblogic 12 to Wildfly 12 JMS Migration: @Resource Injection & java:/ Prefix Explained

Hey there, let's walk through getting your JMS resources properly injected in Wildfly 12, plus clear up why that java:/ prefix is needed.

1. Fix Your @Resource Injection Code

Wildfly follows Jakarta EE (then Java EE) naming conventions strictly, so you'll need to adjust your lookup strings to include the java:/ prefix for local resource access. Here's how your injection should look:

@Resource(lookup = "java:/jms/Queues/MYQUEUE") 
private Queue destination;

@Resource(lookup = "java:/jms/QueueConnectionFactories/MYQUEUECF") 
private QueueConnectionFactory connectionFactory;

Alternatively, you can update your Wildfly configuration to include java:/ entries alongside your existing ones (more on that below), which would let you keep your original lookup strings if you prefer.

2. Complete Your Wildfly JMS Configuration

It looks like your standalone-full.xml connection factory config was cut off—here's the full, properly formatted config for both your queue and connection factory:

<!-- JMS Queue Configuration -->
<jms-queue name="MYQUEUE" entries="jms/Queues/MYQUEUE java:/jms/Queues/MYQUEUE" durable="true"/>

<!-- Connection Factory Configuration -->
<connection-factory name="MYQUEUECF" 
                    entries="jms/QueueConnectionFactories/MYQUEUECF java:/jms/QueueConnectionFactories/MYQUEUECF" 
                    connectors="in-vm"/>

Adding the java:/ prefixed entries here gives you flexibility: you can use either the global name (without prefix) for remote access or the local name (with prefix) for in-VM injection.

3. Why Does Wildfly Require the java:/ Prefix?

The key difference between Weblogic and Wildfly here is how they handle JNDI naming spaces:

  • Weblogic: Its JNDI tree doesn't enforce strict separation between local and global resources. You can look up most resources directly without a namespace prefix because they're exposed in a flat, accessible tree by default.
  • Wildfly: It adheres closely to Java EE naming standards, which split JNDI into distinct namespaces:
    • java:/: This is the local JNDI namespace, reserved for resources that are only accessible within the current JVM (like your in-VM JMS resources). When you use @Resource, the container defaults to looking in this local namespace first.
    • Names without a prefix fall into the global JNDI namespace, which is intended for resources that need to be accessed remotely (e.g., from another server or external client).

So if you don't add the java:/ prefix to your @Resource lookup, Wildfly will only search the global namespace—and unless you've explicitly exposed your JMS resources there (which you might not want for local use), it won't find them.

内容的提问来源于stack exchange,提问作者Markus Fried

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:18:52