Commons Configuration - JNDIConfiguration - How to do it?

I usually use Commons Configuration to manage my application configurations. I used the configuration of the property files. Now I am interested in using JNDIConfiguration, but I can’t understand how this works when reading or searching documentation.

Contextualization, I work in webapps running in JBoss AS.

Where will the properties be stored? In file? some tables in the database?

I would be grateful for any guide at this level, even if it takes the form of links, where I can read valuable information about it.

As a final note, my goal is to free me from the link to the file with hard code for my properties, but also not to force me to have my own config in the database tables. If you have any suggestions on how to do this in another way, you are free to share.

+3
source share
3 answers

Where will the properties be stored? In file? some tables in the database?

As @ewernli mentioned, the Java EE method for adding entries to the JNDI tree is to use it env-entryin the deployment descriptor.

, env-entry , JNDI: JNDIBindingServiceMgr.

jboss-service.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
<server>
   <mbean code="org.jboss.naming.JNDIBindingServiceMgr"
         name="jboss.tests:service=JNDIBindingServiceMgr">
      <attribute name="BindingsConfig" serialDataType="jbxb">
         <jndi:bindings
            xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
            xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd"
            >
            <jndi:binding name="urls/jboss-home">
               <jndi:value type="java.net.URL">http://www.jboss.org</jndi:value>
            </jndi:binding>

            <jndi:binding name="hosts/localhost">
               <jndi:value editor="org.jboss.util.propertyeditor.InetAddressEditor">
                  127.0.0.1
               </jndi:value>
            </jndi:binding>

            <jndi:binding name="maps/testProps">
               <java:properties xmlns:java="urn:jboss:java-properties"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
                  xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
                  <java:property>
                     <java:key>key1</java:key>
                     <java:value>value1</java:value>
                  </java:property>
                  <java:property>
                     <java:key>key2</java:key>
                     <java:value>value2</java:value>
                  </java:property>
               </java:properties>               
            </jndi:binding>
         </jndi:bindings>
      </attribute>
      <depends>jboss:service=Naming</depends>
   </mbean>

</server>

, , , :) .

0

Commons Configuration JNDIConfiguration, , /, Java EE - env-entry web.xml ejb.xml.

<env-entry>
  <env-entry-name>maxExemptions</env-entry-name>
  <env-entry-value>10</env-entry-value>
  <env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>

( JBoss web conf. reference.)

JNDI, .

+1

JNDIConfiguration JNDI ( , JBoss JNDI-). - JNDI, Commons-Configuration .

, JNDI - , , . JBoss -, .

, , , .

java -Dmy.config.path=/my/config.properties com.MyClass

Commons Configuration . hardcoded-paths, .

+1

Source: https://habr.com/ru/post/1730516/


All Articles