001/* 002 * Copyright 2012-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.autoconfigure.jms; 018 019import java.util.Map; 020 021import javax.jms.ConnectionFactory; 022 023import org.springframework.beans.factory.ObjectProvider; 024import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration; 025import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; 026import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; 027import org.springframework.boot.actuate.health.HealthIndicator; 028import org.springframework.boot.actuate.jms.JmsHealthIndicator; 029import org.springframework.boot.autoconfigure.AutoConfigureAfter; 030import org.springframework.boot.autoconfigure.AutoConfigureBefore; 031import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 032import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 033import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 034import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 035import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration; 036import org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration; 037import org.springframework.context.annotation.Bean; 038import org.springframework.context.annotation.Configuration; 039 040/** 041 * {@link EnableAutoConfiguration Auto-configuration} for {@link JmsHealthIndicator}. 042 * 043 * @author Stephane Nicoll 044 * @since 2.0.0 045 */ 046@Configuration 047@ConditionalOnClass(ConnectionFactory.class) 048@ConditionalOnBean(ConnectionFactory.class) 049@ConditionalOnEnabledHealthIndicator("jms") 050@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) 051@AutoConfigureAfter({ ActiveMQAutoConfiguration.class, ArtemisAutoConfiguration.class }) 052public class JmsHealthIndicatorAutoConfiguration extends 053 CompositeHealthIndicatorConfiguration<JmsHealthIndicator, ConnectionFactory> { 054 055 private final Map<String, ConnectionFactory> connectionFactories; 056 057 public JmsHealthIndicatorAutoConfiguration( 058 ObjectProvider<Map<String, ConnectionFactory>> connectionFactories) { 059 this.connectionFactories = connectionFactories.getIfAvailable(); 060 } 061 062 @Bean 063 @ConditionalOnMissingBean(name = "jmsHealthIndicator") 064 public HealthIndicator jmsHealthIndicator() { 065 return createHealthIndicator(this.connectionFactories); 066 } 067 068}