JMSTemplate を利用して、Tibco EMS サーバーとの間で JMS メッセージを送受信する Spring ベースのアプリケーションを開発しています。
現在の実装では、EMS サーバーがダウンしている場合、TomCat の起動中にプロジェクトが失敗します。これは、Spring 構成ファイルに、EMS サーバーに接続しようとしている JMS 関連の Bean があるためです。
したがって、1 つの解決策は、すべての JMS 関連 Bean が必要な場合にのみ開始されるようにすることです (起動時ではありません)。そのために、すべての JMS 関連 Bean の lazy-init 属性を true に設定します。
抜粋:
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager" lazy-init="true">
<property name="internalJmsQueueConnectionFactory"> <ref bean="jmsQueueConnectionFactory" />
</property>
</bean>
<bean id="jmsTemplateWithClientAcknowledge" class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
<property name="internalJmsQueueConnectionFactory" ref="jmsQueueConnectionFactory"/>
</bean>
ここに問題があります。jmsTransactionManagerlazy-init="true"
Bean にのみ設定すると、プロジェクトは問題なく正常にロードされます。ただし、jmsTemplateWithClientAcknowledge Bean も設定するとすぐに、プロジェクトは失敗します。同じ失敗の理由: EMS サーバーに接続できませんでした。lazy-init="true"
ログからのエラー:
org.springframework.beans.factory.BeanCreationException: 'jmsMsgSenderImpl' という名前の Bean の作成中にエラーが発生しました: 自動配線された依存関係の注入に失敗しました。ネストされた例外は org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jms.core.JmsTemplate com.cv.pub.engine.service.impl.JmsMsgSenderImpl.jmsTemplate; です。ネストされた例外は org.springframework.beans.factory.BeanCreationException: ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された名前 'jmsTemplateWithClientAcknowledge' を持つ Bean の作成中にエラーが発生しました: 設定中に Bean 'internalJmsQueueConnectionFactory' への参照を解決できませんBean プロパティ 'connectionFactory'; ネストされた例外は org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' です ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された internalJmsQueueConnectionFactory': Bean プロパティ 'targetConnectionFactory' の設定中に Bean 'targetJmsQueueConnectionFactory' への参照を解決できません。ネストされた例外は org.springframework.beans.factory.BeanCreationException: ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された名前 'targetJmsQueueConnectionFactory' を持つ Bean の作成中にエラーが発生しました: init メソッドの呼び出しに失敗しました。ネストされた例外は javax.naming.ServiceUnavailableException: Failed to query JNDI: Failed to connect to the server at tcp://localhost:7222 [Root exception is javax.jms.JMSException: Failed to connect to the server at tcp://localhost: Failed to connect to the server at tcp://localhost:7222] :7222] Bean プロパティ 'targetConnectionFactory' の設定中に Bean 'targetJmsQueueConnectionFactory' への参照を解決できません。ネストされた例外は org.springframework.beans.factory.BeanCreationException: ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された名前 'targetJmsQueueConnectionFactory' を持つ Bean の作成中にエラーが発生しました: init メソッドの呼び出しに失敗しました。ネストされた例外は javax.naming.ServiceUnavailableException: Failed to query JNDI: Failed to connect to the server at tcp://localhost:7222 [Root exception is javax.jms.JMSException: Failed to connect to the server at tcp://localhost: Failed to connect to the server at tcp://localhost:7222] :7222] Bean プロパティ 'targetConnectionFactory' の設定中に Bean 'targetJmsQueueConnectionFactory' への参照を解決できません。ネストされた例外は org.springframework.beans.factory.BeanCreationException: ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された名前 'targetJmsQueueConnectionFactory' を持つ Bean の作成中にエラーが発生しました: init メソッドの呼び出しに失敗しました。ネストされた例外は javax.naming.ServiceUnavailableException: Failed to query JNDI: Failed to connect to the server at tcp://localhost:7222 [Root exception is javax.jms.JMSException: Failed to connect to the server at tcp://localhost: Failed to connect to the server at tcp://localhost:7222] :7222] ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された targetJmsQueueConnectionFactory : init メソッドの呼び出しに失敗しました。ネストされた例外は javax.naming.ServiceUnavailableException: Failed to query JNDI: Failed to connect to the server at tcp://localhost:7222 [Root exception is javax.jms.JMSException: Failed to connect to the server at tcp://localhost: Failed to connect to the server at tcp://localhost:7222] :7222] ServletContext リソース [/WEB-INF/spring/jms-context.xml] で定義された targetJmsQueueConnectionFactory : init メソッドの呼び出しに失敗しました。ネストされた例外は javax.naming.ServiceUnavailableException: Failed to query JNDI: Failed to connect to the server at tcp://localhost:7222 [Root exception is javax.jms.JMSException: Failed to connect to the server at tcp://localhost: Failed to connect to the server at tcp://localhost:7222] :7222]
あなたの考えと助けに感謝します!