簡體   English   中英

如何在WildFly上運行的應用程序中使用JNDI條目

[英]How do I use a JNDI entry in my application running on WildFly

我正在嘗試使用WildFly命名子系統在Web應用程序中讀取JNDI值,類似於WildFly JNDI參考

這是我的standalone.xml的relevent部分

<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跟蹤仍然發生)。

這可能是什么原因?

確保已完成將cxf與wildfly集成的必要步驟 從您的日志跟蹤看來, cxf似乎正在接管wildfly,以進行@Resource注入。 您完成的配置和代碼是正確的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM