服务器启动时如何加载jboss-tomcat-struts中的config.properties文件
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 JBoss 系统属性服务。配置位于/server//deploy/properties-service.xml 中。这是一个例子:
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: