JBoss: Binding values into JNDI in JBoss EAP 6 similar to JNDIBindingServiceMgr

▼魔方 西西 提交于 2020-01-10 04:18:06

问题


  1. How do I bind an arbitrary string to JNDI in JBoss EAP 6? I used to do it through org.jboss.naming.JNDIBindingServiceMgr MBean in previous EAP version.

  2. Is there anything similar to org.jboss.naming.JNDIBindingServiceMgr in JBoss EAP 6?

  3. We are migrating applications from jboss-5.1.EAP to jboss-eap-6.1. We need to bind some things into JNDI, so applications can look up values of environment variables.

Many thanks.


回答1:


You can do the following:

standalone.xml:

<subsystem xmlns="urn:jboss:domain:naming:1.2">
  <bindings>
    <simple name="java:global/user" value="newUser"/>                
  </bindings>
</subsystem>

and in spring context:

<bean class="java.util.Properties">
  <constructor-arg>
    <map>
      <entry key="user">
         <jee:jndi-lookup jndi-name="java:global/user" />
      </entry>
    </map>
  </constructor-arg>
</bean>



回答2:


In your app configuration you can have things in ejb-jar.xml deployment descriptor like

<javaee:env-entry>
    <javaee:description>JNDI logging context for this app</javaee:description>
    <javaee:env-entry-name>logback/context-name</javaee:env-entry-name>
    <javaee:env-entry-type>java.lang.String</javaee:env-entry-type>
    <javaee:env-entry-value>our-app-context</javaee:env-entry-value>
</javaee:env-entry>

or, if you prefer to have it in the server standalone.xml, do

<subsystem xmlns="urn:jboss:domain:naming:1.1">
    <bindings>
        <simple name="my/jndi/key" value="MyJndiValue"/>
    </bindings>
</subsystem>

the latter (standalone.xml) is a JBoss 7.1 feature, so available in EAP 6.0. In JBoss AS 7.0, a dummy application needs to be used according to this thread.




回答3:


What if simply:

InitialContext ctx = new InitialContext();
ctx.bind("varName", "value");

If you use that code inside of a JBoss instance you can bind variables into jndi. Remember to use the correct format for varName to bind the variable in the desired scope.



来源:https://stackoverflow.com/questions/20212343/jboss-binding-values-into-jndi-in-jboss-eap-6-similar-to-jndibindingservicemgr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!