我是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
可能出现什么问题?
答案 0 :(得分:0)
看看JBoss System Properties Service。配置位于&lt; jboss-home&gt; / server /&lt; server-name&gt; /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>