1

我正在使用动态 Web 项目中的 WEB-INF/resources.xml 文件配置 ActiveMQ 的嵌入式实例,该文件引用外部 activemq.xml 文件。ActiveMQ 使用放置在 Tomcat 的 {$CATALINA_HOME}/conf 目录中的 activemq.xml 的绝对路径按预期启动和运行。将activemq.xml 放入项目的WEB-INF 目录时,Tomcat 无法使用相对路径找到BrokerXmlConfig 文件。

  1. 是否可以将activemq.xml文件与WEB-INF目录下的项目一起打包?
  2. 如果可能,Tomcat如何解析文件的路径?

工作资源.xml

  <resources>
    <Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
        connectionMaxIdleTime = 15 Minutes
        connectionMaxWaitTime = 5 seconds
        poolMaxSize = 10
        poolMinSize = 0
        resourceAdapter = MyJmsResourceAdapter
        transactionSupport = xa
    </Resource>
    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  xbean:file:/absolute/path/to/activemq.xml
        ServerUrl       =  tcp://localhost:61616
    </Resource>
  <resources>

失败的资源.xml

  <resources>
    <Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
        connectionMaxIdleTime = 15 Minutes
        connectionMaxWaitTime = 5 seconds
        poolMaxSize = 10
        poolMinSize = 0
        resourceAdapter = MyJmsResourceAdapter
        transactionSupport = xa
    </Resource>
    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  xbean:file:WEB-INF/activemq.xml
        ServerUrl       =  tcp://localhost:61616
    </Resource>
  <resources>

其他不成功的尝试:

BrokerXmlConfig =  xbean:classpath:WEB-INF/activemq.xml

BrokerXmlConfig =  xbean:file:WEB-INF/activemq.xml

BrokerXmlConfig =  xbean:file:activemq.xml

BrokerXmlConfig =  xbean:file:./activemq.xml

BrokerXmlConfig =  xbean:file:../activemq.xml

BrokerXmlConfig =  xbean:file:conf/activemq.xml
4

1 回答 1

1

我从来没有解决过 xbean 相对路径问题。使用绝对路径有效

BrokerXmlConfig =  xbean:file:/absolute/path/to/activemq.xml

除了路径问题,我最终没有使用单独的 activemq.xml 文件。我刚刚将连接工厂与默认 JMS 资源适配器一起使用。

  <resources>
    <Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
        connectionMaxIdleTime = 15 Minutes
        connectionMaxWaitTime = 5 seconds
        poolMaxSize = 10
        poolMinSize = 0
        resourceAdapter = Default JMS Resource Adapter
        transactionSupport = xa
    </Resource>
  <resources>
于 2019-03-29T14:26:44.177 回答