公共配置 - JNDIConfiguration - 如何?

发布于 2024-08-19 05:50:38 字数 335 浏览 2 评论 0原文

我通常使用 Commons Configuration 来管理我的应用程序配置。我使用了属性文件配置。现在我对使用 JNDIConfiguration 感兴趣,但我无法通过阅读文档或谷歌搜索来理解它是如何工作的。

结合上下文,我正在 JBoss AS 中运行的 Web 应用程序中工作。

属性将存储在哪里?在一个文件中?数据库中的一些表?

我将感谢这个级别的任何指导,即使它是以链接的形式出现的,我可以在其中阅读一些有关它的有价值的信息。

最后一点,我的目标是让我不必将文件与属性的硬编码路径链接起来,但也不强迫我将配置放在数据库表中。如果您对如何以其他方式做到这一点有任何建议,请随意分享。

I usually use Commons Configuration for manage my applications configs. I have used properties files configuration. Now I'm interested in using a JNDIConfiguration but I'm not able to understand how this works reading the documentation or googling it.

Contextualizing, I'm working in webapps running in an JBoss AS.

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

I will be grateful for any guidance at this level even if it comes in shape of links where I can read some valuable information about it.

As a final note my goal is to free me of linking a file with a hardcoded path for my properties, but also don't force me to have my config in database tables. If you have any suggestions on how to do that in some other way be free to share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

给不了的爱 2024-08-26 05:50:38

JNDIConfiguration 查找 JNDI 服务器(在您的例子中为 JBoss JNDI 服务器)上的配置数据。但是,您首先仍然需要一种将数据输入 JNDI 服务器的方法,而 Commons-Configuration 无法帮助您实现这一点。

在我看来,JNDI 并不是您想要的,它只是稍微解决了问题。 JBoss 仍然需要在某处存储配置数据,因此您仍然会遇到相同的基本问题。

如果您不需要硬编码的文件路径,并且不需要数据库,那么我建议您通过系统属性传入属性文件的位置,例如

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

然后将该位置传递给 Commons Configuration 并让它加载你的配置就是这样。没有硬编码路径,没有数据库。

JNDIConfiguration looks up the configuration data on a JNDI server (in your case, the JBoss JNDI server). However, you still need a way of getting that data into the JNDI server in the first place, and Commons-Configuration won't help you with that.

It sounds to me that JNDI isn't what you want, it's just pushing the problem around a bit. JBoss still needs to store the configuration data somewhere, so you'll still have the same basic problem.

If you don't want hard-coded file paths, and you don't want a database, then I suggest you pass in the location of the properties file via a system property, e.g.

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

Then pass that location to Commons Configuration and let it load your config that way. No hardcoded-paths, no database.

拥抱影子 2024-08-26 05:50:38

我对 Commons Configuration 和 JNDIConfiguration 不太了解,但如果您想要的是一组键/值对,则按照 Java 执行此操作的标准方法EE规范,是在web.xmlejb.xml中使用env-entry

<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 这些值绑定在 JNDI 中,

以便可以查找或注入。

I don't know much about Commons Configuration and JNDIConfiguration, but if what you want is a set of key/value pairs, the standard way of doing this as per the Java EE specs, is to use env-entry in the web.xml or 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>

(example taken from JBoss web conf. reference.)

These values are bound in the JNDI so they can be looked up or injected.

笑咖 2024-08-26 05:50:38

属性将存储在哪里?在一个文件中?数据库中的一些表?

正如 @ewernli 提到的,在 JNDI 树中添加条目的 Java EE 方法是在部署描述符中使用 env-entry

现在,如果您不想在多个部署描述符中重复相同的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>

如果这不是您要查找的内容,那么我不明白您要查找的内容:) 在这种情况下,您也许应该澄清一下它。

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

As @ewernli mentioned, the Java EE way to add entries in the JNDI tree is to use env-entry in your deployment descriptor(s).

Now, if you don't want to repeat the same env-entry in several deployment descriptors, then there is a service for specifying global JNDI bindings: JNDIBindingServiceMgr.

Below, the provided jboss-service.xml example:

<?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>

If this is not what you are looking for, then I don't understand what you're looking for :) In that case, you should maybe clarify it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文