服务器启动时如何加载jboss-tomcat-struts中的config.properties文件

发布于 2024-11-23 15:09:12 字数 1617 浏览 1 评论 0原文

我是 Java EE 初学者。我正在尝试修改系统(jboss-3.2.3、tomcat-5.0.28、struts-1.1)。我需要在 jboss/tomcat 启动时加载 config.properties 文件,因此这些属性可用于整个应用程序。

这就是我被要求做的:“第一次加载 .properties(仅一次),因此,当需要读取时它已经在内存中”。

我怎样才能做到这一点?我可以从哪里开始?

编辑: 我尝试从properties-service.xml加载

<?xml version="1.0" encoding="UTF-8"?>
<server>
    <mbean code="org.jboss.varia.property.PropertyEditorManagerService" name="jboss:type=Service,name=PropertyEditorManager"></mbean>

    <mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties">
        <attribute name="URLList">
            ./conf/somelocal.properties
        </attribute>
        <attribute name="Properties">
            my.project.property=This is the value of my property
            my.project.anotherProperty=This is the value of my other property
        </attribute>
    </mbean>
</server>

看起来JBOSS加载正确:

2011-08-01 11:54:29,736 [INFO ] property.SystemPropertiesService - Loaded system properties from: file:/D:/jboss-3.2.3/server/default/conf/somelocal.properties
2011-08-01 11:54:29,736 [INFO ] property.PropertyEditorManagerService - Started jboss:type=Service,name=PropertyEditorManager
2011-08-01 11:54:29,736 [INFO ] property.SystemPropertiesService - Started jboss:type=Service,name=SystemProperties

但是当我尝试使用该属性时返回null:

String myProperty = System.getProperty("my.project.property");
System.out.println(myProperty); // null

可能出了什么问题?

I'm Java EE beginner. I'm trying to modify a system (jboss-3.2.3, tomcat-5.0.28, struts-1.1). I need to load a config.properties file when jboss/tomcat starts, so, the properties could be available for the entire application.

This is what I was asked to do: "Load the .properties the first time (only one time) so, when it need to be readed is already in memory".

How can I do that? Where can I start?

EDIT:
I trying to load from properties-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<server>
    <mbean code="org.jboss.varia.property.PropertyEditorManagerService" name="jboss:type=Service,name=PropertyEditorManager"></mbean>

    <mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties">
        <attribute name="URLList">
            ./conf/somelocal.properties
        </attribute>
        <attribute name="Properties">
            my.project.property=This is the value of my property
            my.project.anotherProperty=This is the value of my other property
        </attribute>
    </mbean>
</server>

Looks like JBOSS loads correctly:

2011-08-01 11:54:29,736 [INFO ] property.SystemPropertiesService - Loaded system properties from: file:/D:/jboss-3.2.3/server/default/conf/somelocal.properties
2011-08-01 11:54:29,736 [INFO ] property.PropertyEditorManagerService - Started jboss:type=Service,name=PropertyEditorManager
2011-08-01 11:54:29,736 [INFO ] property.SystemPropertiesService - Started jboss:type=Service,name=SystemProperties

But when I tried to use the property returns null:

String myProperty = System.getProperty("my.project.property");
System.out.println(myProperty); // null

What could be wrong?

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

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

发布评论

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

评论(1

清风不识月 2024-11-30 15:09:12

看一下 JBoss 系统属性服务。配置位于 /server//deploy/properties-service.xml中。这是一个例子:

<server>
    <mbean code="org.jboss.varia.property.SystemPropertiesService"
           name="jboss.util:type=Service,name=SystemProperties">

        <!-- Load properties from each of the given comma seperated URLs -->
        <attribute name="URLList">
            http://somehost/some-location.properties,
            ./conf/somelocal.properties
        </attribute>

        <!-- Set propertuies using the properties file style. -->
        <attribute name="Properties">
            property1=This is the value of my property
            property2=This is the value of my other property
        </attribute>

    </mbean>
</server>

Take a look at the JBoss System Properties Service. The configuration is in <jboss-home>/server/<server-name>/deploy/properties-service.xml. Here's an example:

<server>
    <mbean code="org.jboss.varia.property.SystemPropertiesService"
           name="jboss.util:type=Service,name=SystemProperties">

        <!-- Load properties from each of the given comma seperated URLs -->
        <attribute name="URLList">
            http://somehost/some-location.properties,
            ./conf/somelocal.properties
        </attribute>

        <!-- Set propertuies using the properties file style. -->
        <attribute name="Properties">
            property1=This is the value of my property
            property2=This is the value of my other property
        </attribute>

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