2014-10-06 113 views
0
的NameNotFoundException我

具有以下結構使用JNDI配置的EJB:

MyProject.ear (module name) MyProjectEar 
    |----- lib 
    |----- META-INF 
    |----- MyProject.war 
    |----- MyProject.jar (module name) MyProject 

在MyProject.jar我有幾個的EJB,包括mypackages.myproject.ejb.impl.ConfigManager(其在mypackages.myproject.ejb.local.ConfigManagerLocal本地接口)

ConfigManager

@Singleton 
@Startup 
public class GestorConfiguracion implements GestorConfiguracionLocal { 

    @PostConstruct 
    private void init() { 
    Context ctx = null; 
    try { 
     ctx = new InitialContext(); 
     ctx = (Context) ctx.lookup("java:comp"); 
    } catch (Exception e) { 
     return; 
    } 
    try { 
     String jndiEnv = (String) ctx.lookup("myProject/srv/environment"); 
    } catch (Exception e) { 
     log.log(Level.WARNING, "Exception in jndienv", e); 
    } 
    try { 
     appVersion = (String) ctx.lookup("myProject/buildVersion")); 
    } catch (Exception e) { 
     log.log(Level.WARNING, "Exception in buildversion", e); 
    } 

myProject/srv/environment對於服務器來說是本地的(所以它在EAR構建之間不會改變),所以它被設置在standalone.xml,如下

<subsystem xmlns="urn:jboss:domain:naming:2.0"> 
    <bindings> 
    <simple name="java:/env/myProject/srv/environment" value="DEV"/> 
    </bindings> 
    <remote-naming/> 
</subsystem> 

myProject/buildVersion將在每個建築物而改變,通過將env-entry-valueenv-entry

我已經嘗試了兩種技術途徑:

1)添加到MyProject.ear/META-INF/application.xml中的臺詞:

<env-entry> 
    <env-entry-name>myProject/buildVersion</env-entry-name> 
    <env-entry-type>java.lang.String</env-entry-type> 
    <env-entry-value>0.0.1</env-entry-value> 
</env-entry> 

<resource-ref> 
    <res-ref-name>myProject/srv/environment</res-ref-name> 
    <res-type>java.lang.String</res-type> 
    <lookup-name>java:/env/myProject/srv/environment</lookup-name> 
</resource-ref> 

我只得到javax.naming.NameNotFoundException,與消息:

  • 服務jboss.naming.context.java.comp.MyProjectEar.MyProject.ConfigManager.myProject.buildVersion

  • 服務jboss.naming.context.java.comp.MyProjectEar.MyProject.ConfigManager.myProject.srv.environment

回答

0

它結束是,我一直在尋找在錯誤的上下文。

  • 如果env-entryresource-ref標籤,其中在EJB項目ejb-jar.xml中,我會發現他們在java:comp/env/(V.G。,java:comp/env/myProject/buildVersionjava:comp/env/myProject/srv/environment);我需要第一查找更改爲ctx = (Context) ctx.lookup("java:comp/env");

  • 如果env-entryresource-ref標籤,其中在EAR項目的application.xml,我會發現他們在java:app/env/(V.G。,java:app/env/myProject/buildVersionjava:app/env/myProject/srv/environment);我需要將第一個查找更改爲ctx = (Context) ctx.lookup("java:app/env");