我是 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
有什么问题吗?
最佳答案
看看 JBoss System Properties Service .配置位于
<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>
关于java - 服务器启动时如何在jboss-tomcat-struts中加载config.properties文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6701129/