具有以下結構使用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-value
到env-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