jboss-web.xml中的系统属性引用未在服务器启动时解析

时间:2011-06-09 07:55:47

标签: java jboss jboss5.x jboss-web

我正在使用JBoss 5和系统属性服务来设置我的app(ear with war)需要的一些系统属性。其中一个是jboss-web.xml中引用的虚拟主机的名称:

<jboss-web>
  <context-root>/</context-root>
  <virtual-host>${my.host.system.prop}</virtual-host>
  ...
  <depends>jboss:type=Service,name=SystemProperties</depends>
</jboss-web> 

请注意对SystemProperties服务的依赖性。

但是在服务器启动时,我的应用程序在设置系统属性之前加载。通过触摸耳朵重新部署将其分类。有趣的是,我可以从日志中看到SystemProperties服务确实在我的应用程序部署之前加载了。

有人有什么想法吗?如果我可以提供帮助,我不想在JAVA_OPTS中设置道具。

2 个答案:

答案 0 :(得分:3)

您的SystemProperties mbean在哪里定义?我遇到了与JBoss 4.2类似的问题,我的问题通过将mbean定义放入conf / jboss-service.xml而不是将其放入deploy目录来解决。这导致SystemProperties mbean在jboss启动时加载。

此解决方案的唯一缺点是您失去了SystemProperties mbean的热部署能力。

答案 1 :(得分:0)

将您的Systemproperties部署为自己的SystempropertiesService,例如作为文件“myapp-properties-service.xml”

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
    name="jboss:type=Service,name=myAppSystemProperties">

            <!-- relative path of server profile, 
                 comma separated list of propertyfiles-->
    <attribute name="URLList">
        ./conf/props/myapp-system.properties,./conf/props/myapp-otherstuff.properties
    </attribute>
</mbean>

现在确保在应用程序执行之前启用myAppSystemPropertiesService。我们通过将其声明放入“deployers”-dir而不是“deploy”-dir来解决这个问题。在“deployers”文件夹中声明的服务在“deploy”中的服务之前部署。 E.g:

jboss-5.1.0.GA/server/default/deployers/myapp-properties-service.xml
jboss-5.1.0.GA/server/default/props/myapp-system.properties
jboss-5.1.0.GA/server/default/props/myapp-otherstuff.properties
相关问题