如何在我的WildFly上运行的应用程序中使用JNDI条目

时间:2015-08-28 00:56:47

标签: jndi wildfly

我正在尝试使用WildFly命名子系统在我的Web应用程序中读取JNDI值,类似于WildFly JNDI Reference

以下是我的standalone.xml的相关部分

<subsystem xmlns="urn:jboss:domain:naming:2.0" >
  <bindings>
    <simple name="java:global/myId" value="ID001" type="java.lang.String" />
  </bindings>
  <remote-naming/>
</subsystem>

这是我用来查找JNDI的代码

@Resource(lookup = "java:global/myId")
private String myId;

当我部署时,字段myId没有设置,我在控制台上得到以下输出:

17:18:43,115 INFO  [org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-1) Creating Service {http://example.com}MyAppService from class com.abc.MyAppPort
17:18:43,428 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-1) Setting the server's publish address to be http://localhost:9080/MA/MyAppService
17:18:43,443 FINE  [org.apache.cxf.resource.DefaultResourceManager] (MSC service thread 1-1) resolving resource <com.example.impl.MyApp/myId> type <class java.lang.String>
17:18:43,443 FINE  [org.apache.cxf.resource.DefaultResourceManager] (MSC service thread 1-1) resolving resource <null> type <class java.lang.String>
17:18:43,443 INFO  [org.apache.cxf.common.injection.ResourceInjector] (MSC service thread 1-1) failed to resolve resource com.example.impl.MyApp/myId

更新:如果我在jboss-web.xml中进行查找,如下所示:

<resource-env-ref>
  <resource-env-ref-name>myId</resource-env-ref-name>
  <resource-env-ref-type>java.lang.String</resource-env-ref-name>
  <lookup-name>java:global/myId</lookup-name>
</resource-env-ref>

并从注释中删除查找:

@Resource
private String myId;

myId按预期设置(上面的cxf跟踪仍然发生)。

这可能是什么原因?

1 个答案:

答案 0 :(得分:1)

确保您已完成integrate cxf with wildfly所需的操作。从您的日志跟踪看来, cxf正在接管wildfly 以继续@Resource注入。您完成的配置和代码是正确的。

相关问题