【问题标题】:System property reference in jboss-web.xml not resolved on server startupjboss-web.xml 中的系统属性引用在服务器启动时未解析
【发布时间】:2012-04-05 20:11:50
【问题描述】:

我正在使用 JBoss 5 和系统属性服务来设置我的应用程序(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 中设置道具。

【问题讨论】:

  • 如果可能,您可以尝试将依赖项向上移动以包含整个 EAR,而不是单个 WAR。

标签: java jboss jboss5.x jboss-web


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    将您的 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 来解决这个问题。在“部署者”文件夹中声明的服务在“部署”中的服务之前部署。例如:

    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
    

    【讨论】:

      猜你喜欢
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2011-01-30
      相关资源
      最近更新 更多