公共配置 - JNDIConfiguration - 如何?
我通常使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JNDIConfiguration
查找 JNDI 服务器(在您的例子中为 JBoss JNDI 服务器)上的配置数据。但是,您首先仍然需要一种将数据输入 JNDI 服务器的方法,而 Commons-Configuration 无法帮助您实现这一点。在我看来,JNDI 并不是您想要的,它只是稍微解决了问题。 JBoss 仍然需要在某处存储配置数据,因此您仍然会遇到相同的基本问题。
如果您不需要硬编码的文件路径,并且不需要数据库,那么我建议您通过系统属性传入属性文件的位置,例如
然后将该位置传递给 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.
Then pass that location to Commons Configuration and let it load your config that way. No hardcoded-paths, no database.
我对 Commons Configuration 和 JNDIConfiguration 不太了解,但如果您想要的是一组键/值对,则按照 Java 执行此操作的标准方法EE规范,是在
web.xml
或ejb.xml
中使用env-entry
。(示例取自 JBoss web 这些值绑定在 JNDI 中,
以便可以查找或注入。
I don't know much about
Commons Configuration
andJNDIConfiguration
, 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 useenv-entry
in theweb.xml
orejb.xml
.(example taken from JBoss web conf. reference.)
These values are bound in the JNDI so they can be looked up or injected.
正如 @ewernli 提到的,在 JNDI 树中添加条目的 Java EE 方法是在部署描述符中使用
env-entry
。现在,如果您不想在多个部署描述符中重复相同的
env-entry
,那么有一个用于指定全局 JNDI 绑定的服务:JNDIBindingServiceMgr
。下面是提供的
jboss-service.xml
示例:如果这不是您要查找的内容,那么我不明白您要查找的内容:) 在这种情况下,您也许应该澄清一下它。
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: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.