2012-05-29 27 views
0

我在我的類路徑中的jndi.properties文件中定義了jms連接設置,該文件用於在本地開發環境中連接到ActiveMQ。我想將這個文件重命名爲「activemq.jndi.properties」,因爲我打算給WebsphereMQ另外設置jms連接設置(比如說webshperemq.jndi.properties)。不過,在我的applicationContext.xml中查看activemq.jndi.properties時,我目前還沒有成功告訴spring。根據配置文件在彈簧應用程序上下文中加載不同的jndi.properties文件

這裏是我的applicationContext.xml的片段,其適用於jndi.properties

<!-- Define how to connect to the Message Queueing system --> 
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="${jms.connectionFactory}" /> 
    <property name="resourceRef" value="true" /> 
</bean> 

<bean id="defaultDestination" class="org.springframework.jndi.JndiObjectFactoryBean"> 
    <property name="jndiName" value="${jms.topic}" /> 
    <property name="resourceRef" value="true" /> 
</bean> 

<!-- Define a connection template that links to the factory --> 
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> 
    <property name="connectionFactory" ref="connectionFactory" /> 
    <property name="defaultDestination" ref="defaultDestination" /> 
    <property name="receiveTimeout" value="6000" /> 
</bean> 

兩個$ {jm​​s.connectionFactory}和$ {} jms.topic正在從行家過濾。任何關於需要在我的applicationContext.xml中進行更改以使其從activemq.jndi.properties加載的輸入將非常感激。

謝謝!

回答

1

嗯,我想你應該配置maven資源,以便根據配置文件使用另一個配置文件,而不是改變Spring配置文件中的任何內容。

例如:

<profiles> 
    <profile> 
     <id>local</id> 
     <build> 
      <resources> 
       <resource> 
        <directory>src/main/resources</directory> 
        <filtering>true</filtering> 
        <includes> 
         <include>jndi.properties</exclude> 
        </excludes> 
       </resource> 
      </resources> 
     </build> 
    </profile> 
    <profile> 
     <id>webshpere</id> 
     <build> 
      <resources> 
       <resource> 
        <directory>src/main/resources</directory> 
        <filtering>true</filtering> 
        <includes> 
         <include>webshperemq.jndi.properties</exclude> 
        </excludes> 
       </resource> 
      </resources> 
     </build> 
    </profile> 
</profiles> 
+0

嗨jddsantaella,感謝您的輸入,但是元素不是行家元素內有效,所以你的建議上面就不會工作。基本上,如果我將jndi.properties重命名爲activemq.jndi.properties,如何告訴spring(如果可能的話)「查看」activemq.jndi.properties而不是jndi.properties(這是Spring將加載的默認值)? –

+0

資源定義在配置文件內有效。我已經更新了我的答案,向您展示了整個結構 – jddsantaella

相關問題