Avoid using reflection when creating composite health contributors
Closes gh-32541
This commit is contained in:
parent
e2dd0ef9a4
commit
bcb5e84129
|
@ -44,6 +44,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class RabbitHealthContributorAutoConfiguration
|
public class RabbitHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<RabbitHealthIndicator, RabbitTemplate> {
|
extends CompositeHealthContributorConfiguration<RabbitHealthIndicator, RabbitTemplate> {
|
||||||
|
|
||||||
|
public RabbitHealthContributorAutoConfiguration() {
|
||||||
|
super(RabbitHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "rabbitHealthIndicator", "rabbitHealthContributor" })
|
@ConditionalOnMissingBean(name = { "rabbitHealthIndicator", "rabbitHealthContributor" })
|
||||||
public HealthContributor rabbitHealthContributor(Map<String, RabbitTemplate> rabbitTemplates) {
|
public HealthContributor rabbitHealthContributor(Map<String, RabbitTemplate> rabbitTemplates) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,6 +43,10 @@ class CassandraHealthContributorConfigurations {
|
||||||
static class CassandraDriverConfiguration
|
static class CassandraDriverConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<CassandraDriverHealthIndicator, CqlSession> {
|
extends CompositeHealthContributorConfiguration<CassandraDriverHealthIndicator, CqlSession> {
|
||||||
|
|
||||||
|
CassandraDriverConfiguration() {
|
||||||
|
super(CassandraDriverHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||||
HealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
HealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
||||||
|
@ -56,6 +60,10 @@ class CassandraHealthContributorConfigurations {
|
||||||
static class CassandraReactiveDriverConfiguration extends
|
static class CassandraReactiveDriverConfiguration extends
|
||||||
CompositeReactiveHealthContributorConfiguration<CassandraDriverReactiveHealthIndicator, CqlSession> {
|
CompositeReactiveHealthContributorConfiguration<CassandraDriverReactiveHealthIndicator, CqlSession> {
|
||||||
|
|
||||||
|
CassandraReactiveDriverConfiguration() {
|
||||||
|
super(CassandraDriverReactiveHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||||
ReactiveHealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
ReactiveHealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
||||||
|
|
|
@ -49,6 +49,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class CouchbaseHealthContributorAutoConfiguration
|
public class CouchbaseHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<CouchbaseHealthIndicator, Cluster> {
|
extends CompositeHealthContributorConfiguration<CouchbaseHealthIndicator, Cluster> {
|
||||||
|
|
||||||
|
public CouchbaseHealthContributorAutoConfiguration() {
|
||||||
|
super(CouchbaseHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
|
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
|
||||||
public HealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
public HealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
||||||
|
|
|
@ -48,6 +48,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class CouchbaseReactiveHealthContributorAutoConfiguration
|
public class CouchbaseReactiveHealthContributorAutoConfiguration
|
||||||
extends CompositeReactiveHealthContributorConfiguration<CouchbaseReactiveHealthIndicator, Cluster> {
|
extends CompositeReactiveHealthContributorConfiguration<CouchbaseReactiveHealthIndicator, Cluster> {
|
||||||
|
|
||||||
|
public CouchbaseReactiveHealthContributorAutoConfiguration() {
|
||||||
|
super(CouchbaseReactiveHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
|
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
|
||||||
public ReactiveHealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
public ReactiveHealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
||||||
|
|
|
@ -48,6 +48,10 @@ import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchCl
|
||||||
public class ElasticsearchReactiveHealthContributorAutoConfiguration extends
|
public class ElasticsearchReactiveHealthContributorAutoConfiguration extends
|
||||||
CompositeReactiveHealthContributorConfiguration<ElasticsearchReactiveHealthIndicator, ReactiveElasticsearchClient> {
|
CompositeReactiveHealthContributorConfiguration<ElasticsearchReactiveHealthIndicator, ReactiveElasticsearchClient> {
|
||||||
|
|
||||||
|
public ElasticsearchReactiveHealthContributorAutoConfiguration() {
|
||||||
|
super(ElasticsearchReactiveHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
|
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
|
||||||
public ReactiveHealthContributor elasticsearchHealthContributor(Map<String, ReactiveElasticsearchClient> clients) {
|
public ReactiveHealthContributor elasticsearchHealthContributor(Map<String, ReactiveElasticsearchClient> clients) {
|
||||||
|
|
|
@ -46,6 +46,10 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
public class MongoHealthContributorAutoConfiguration
|
public class MongoHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<MongoHealthIndicator, MongoTemplate> {
|
extends CompositeHealthContributorConfiguration<MongoHealthIndicator, MongoTemplate> {
|
||||||
|
|
||||||
|
public MongoHealthContributorAutoConfiguration() {
|
||||||
|
super(MongoHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
|
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
|
||||||
public HealthContributor mongoHealthContributor(Map<String, MongoTemplate> mongoTemplates) {
|
public HealthContributor mongoHealthContributor(Map<String, MongoTemplate> mongoTemplates) {
|
||||||
|
|
|
@ -47,6 +47,10 @@ import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||||
public class MongoReactiveHealthContributorAutoConfiguration
|
public class MongoReactiveHealthContributorAutoConfiguration
|
||||||
extends CompositeReactiveHealthContributorConfiguration<MongoReactiveHealthIndicator, ReactiveMongoTemplate> {
|
extends CompositeReactiveHealthContributorConfiguration<MongoReactiveHealthIndicator, ReactiveMongoTemplate> {
|
||||||
|
|
||||||
|
public MongoReactiveHealthContributorAutoConfiguration() {
|
||||||
|
super(MongoReactiveHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
|
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
|
||||||
public ReactiveHealthContributor mongoHealthContributor(Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
|
public ReactiveHealthContributor mongoHealthContributor(Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
|
||||||
|
|
|
@ -47,6 +47,10 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
public class RedisHealthContributorAutoConfiguration
|
public class RedisHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {
|
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {
|
||||||
|
|
||||||
|
RedisHealthContributorAutoConfiguration() {
|
||||||
|
super(RedisHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
|
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
|
||||||
public HealthContributor redisHealthContributor(Map<String, RedisConnectionFactory> redisConnectionFactories) {
|
public HealthContributor redisHealthContributor(Map<String, RedisConnectionFactory> redisConnectionFactories) {
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class RedisReactiveHealthContributorAutoConfiguration extends
|
||||||
|
|
||||||
RedisReactiveHealthContributorAutoConfiguration(
|
RedisReactiveHealthContributorAutoConfiguration(
|
||||||
Map<String, ReactiveRedisConnectionFactory> redisConnectionFactories) {
|
Map<String, ReactiveRedisConnectionFactory> redisConnectionFactories) {
|
||||||
|
super(RedisReactiveHealthIndicator::new);
|
||||||
this.redisConnectionFactories = redisConnectionFactories;
|
this.redisConnectionFactories = redisConnectionFactories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class ElasticsearchRestHealthContributorAutoConfiguration
|
public class ElasticsearchRestHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<ElasticsearchRestClientHealthIndicator, RestClient> {
|
extends CompositeHealthContributorConfiguration<ElasticsearchRestClientHealthIndicator, RestClient> {
|
||||||
|
|
||||||
|
public ElasticsearchRestHealthContributorAutoConfiguration() {
|
||||||
|
super(ElasticsearchRestClientHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
|
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
|
||||||
public HealthContributor elasticsearchHealthContributor(Map<String, RestClient> clients) {
|
public HealthContributor elasticsearchHealthContributor(Map<String, RestClient> clients) {
|
||||||
|
|
|
@ -46,6 +46,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class HazelcastHealthContributorAutoConfiguration
|
public class HazelcastHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<HazelcastHealthIndicator, HazelcastInstance> {
|
extends CompositeHealthContributorConfiguration<HazelcastHealthIndicator, HazelcastInstance> {
|
||||||
|
|
||||||
|
public HazelcastHealthContributorAutoConfiguration() {
|
||||||
|
super(HazelcastHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "hazelcastHealthIndicator", "hazelcastHealthContributor" })
|
@ConditionalOnMissingBean(name = { "hazelcastHealthIndicator", "hazelcastHealthContributor" })
|
||||||
public HealthContributor hazelcastHealthContributor(Map<String, HazelcastInstance> hazelcastInstances) {
|
public HealthContributor hazelcastHealthContributor(Map<String, HazelcastInstance> hazelcastInstances) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.health;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.core.ResolvableType;
|
import org.springframework.core.ResolvableType;
|
||||||
|
@ -36,16 +37,41 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractCompositeHealthContributorConfiguration<C, I extends C, B> {
|
public abstract class AbstractCompositeHealthContributorConfiguration<C, I extends C, B> {
|
||||||
|
|
||||||
private final Class<?> indicatorType;
|
private final Function<B, I> indicatorFactory;
|
||||||
|
|
||||||
private final Class<?> beanType;
|
/**
|
||||||
|
* Creates a {@code AbstractCompositeHealthContributorConfiguration} that will use
|
||||||
AbstractCompositeHealthContributorConfiguration() {
|
* reflection to create health indicator instances.
|
||||||
|
* @deprecated since 3.0.0 in favor of
|
||||||
|
* {@link #AbstractCompositeHealthContributorConfiguration(Function)}
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "3.0.0", forRemoval = true)
|
||||||
|
protected AbstractCompositeHealthContributorConfiguration() {
|
||||||
ResolvableType type = ResolvableType.forClass(AbstractCompositeHealthContributorConfiguration.class,
|
ResolvableType type = ResolvableType.forClass(AbstractCompositeHealthContributorConfiguration.class,
|
||||||
getClass());
|
getClass());
|
||||||
this.indicatorType = type.resolveGeneric(1);
|
Class<?> indicatorType = type.resolveGeneric(1);
|
||||||
this.beanType = type.resolveGeneric(2);
|
Class<?> beanType = type.resolveGeneric(2);
|
||||||
|
this.indicatorFactory = (bean) -> {
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Constructor<I> constructor = (Constructor<I>) indicatorType.getDeclaredConstructor(beanType);
|
||||||
|
return BeanUtils.instantiateClass(constructor, bean);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Unable to create health indicator " + indicatorType + " for bean type " + beanType, ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@code AbstractCompositeHealthContributorConfiguration} that will use the
|
||||||
|
* given {@code indicatorFactory} to create health indicator instances.
|
||||||
|
* @param indicatorFactory the function to create health indicators
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
protected AbstractCompositeHealthContributorConfiguration(Function<B, I> indicatorFactory) {
|
||||||
|
this.indicatorFactory = indicatorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final C createContributor(Map<String, B> beans) {
|
protected final C createContributor(Map<String, B> beans) {
|
||||||
|
@ -58,16 +84,8 @@ public abstract class AbstractCompositeHealthContributorConfiguration<C, I exten
|
||||||
|
|
||||||
protected abstract C createComposite(Map<String, B> beans);
|
protected abstract C createComposite(Map<String, B> beans);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected I createIndicator(B bean) {
|
protected I createIndicator(B bean) {
|
||||||
try {
|
return this.indicatorFactory.apply(bean);
|
||||||
Constructor<I> constructor = (Constructor<I>) this.indicatorType.getDeclaredConstructor(this.beanType);
|
|
||||||
return BeanUtils.instantiateClass(constructor, bean);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Unable to create health indicator " + this.indicatorType + " for bean type " + this.beanType, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure.health;
|
package org.springframework.boot.actuate.autoconfigure.health;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.CompositeHealthContributor;
|
import org.springframework.boot.actuate.health.CompositeHealthContributor;
|
||||||
import org.springframework.boot.actuate.health.HealthContributor;
|
import org.springframework.boot.actuate.health.HealthContributor;
|
||||||
|
@ -35,6 +36,27 @@ import org.springframework.boot.actuate.health.HealthIndicator;
|
||||||
public abstract class CompositeHealthContributorConfiguration<I extends HealthIndicator, B>
|
public abstract class CompositeHealthContributorConfiguration<I extends HealthIndicator, B>
|
||||||
extends AbstractCompositeHealthContributorConfiguration<HealthContributor, I, B> {
|
extends AbstractCompositeHealthContributorConfiguration<HealthContributor, I, B> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@code CompositeHealthContributorConfiguration} that will use reflection
|
||||||
|
* to create {@link HealthIndicator} instances.
|
||||||
|
* @deprecated since 3.0.0 in favor of
|
||||||
|
* {@link #CompositeHealthContributorConfiguration(Function)}
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "3.0.0", forRemoval = true)
|
||||||
|
public CompositeHealthContributorConfiguration() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@code CompositeHealthContributorConfiguration} that will use the given
|
||||||
|
* {@code indicatorFactory} to create {@link HealthIndicator} instances.
|
||||||
|
* @param indicatorFactory the function to create health indicator instances
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
public CompositeHealthContributorConfiguration(Function<B, I> indicatorFactory) {
|
||||||
|
super(indicatorFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final HealthContributor createComposite(Map<String, B> beans) {
|
protected final HealthContributor createComposite(Map<String, B> beans) {
|
||||||
return CompositeHealthContributor.fromMap(beans, this::createIndicator);
|
return CompositeHealthContributor.fromMap(beans, this::createIndicator);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure.health;
|
package org.springframework.boot.actuate.autoconfigure.health;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor;
|
import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor;
|
||||||
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
|
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
|
||||||
|
@ -35,6 +36,27 @@ import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
||||||
public abstract class CompositeReactiveHealthContributorConfiguration<I extends ReactiveHealthIndicator, B>
|
public abstract class CompositeReactiveHealthContributorConfiguration<I extends ReactiveHealthIndicator, B>
|
||||||
extends AbstractCompositeHealthContributorConfiguration<ReactiveHealthContributor, I, B> {
|
extends AbstractCompositeHealthContributorConfiguration<ReactiveHealthContributor, I, B> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@code CompositeReactiveHealthContributorConfiguration} that will use
|
||||||
|
* reflection to create {@link ReactiveHealthIndicator} instances.
|
||||||
|
* @deprecated since 3.0.0 in favor of
|
||||||
|
* {@link #CompositeReactiveHealthContributorConfiguration(Function)}
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "3.0.0", forRemoval = true)
|
||||||
|
public CompositeReactiveHealthContributorConfiguration() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@code CompositeReactiveHealthContributorConfiguration} that will use the
|
||||||
|
* given {@code indicatorFactory} to create {@link ReactiveHealthIndicator} instances.
|
||||||
|
* @param indicatorFactory the function to create health indicator instances
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
public CompositeReactiveHealthContributorConfiguration(Function<B, I> indicatorFactory) {
|
||||||
|
super(indicatorFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final ReactiveHealthContributor createComposite(Map<String, B> beans) {
|
protected final ReactiveHealthContributor createComposite(Map<String, B> beans) {
|
||||||
return CompositeReactiveHealthContributor.fromMap(beans, this::createIndicator);
|
return CompositeReactiveHealthContributor.fromMap(beans, this::createIndicator);
|
||||||
|
|
|
@ -45,6 +45,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class InfluxDbHealthContributorAutoConfiguration
|
public class InfluxDbHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<InfluxDbHealthIndicator, InfluxDB> {
|
extends CompositeHealthContributorConfiguration<InfluxDbHealthIndicator, InfluxDB> {
|
||||||
|
|
||||||
|
public InfluxDbHealthContributorAutoConfiguration() {
|
||||||
|
super(InfluxDbHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "influxDbHealthIndicator", "influxDbHealthContributor" })
|
@ConditionalOnMissingBean(name = { "influxDbHealthIndicator", "influxDbHealthContributor" })
|
||||||
public HealthContributor influxDbHealthContributor(Map<String, InfluxDB> influxDbs) {
|
public HealthContributor influxDbHealthContributor(Map<String, InfluxDB> influxDbs) {
|
||||||
|
|
|
@ -45,6 +45,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
public class JmsHealthContributorAutoConfiguration
|
public class JmsHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<JmsHealthIndicator, ConnectionFactory> {
|
extends CompositeHealthContributorConfiguration<JmsHealthIndicator, ConnectionFactory> {
|
||||||
|
|
||||||
|
public JmsHealthContributorAutoConfiguration() {
|
||||||
|
super(JmsHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "jmsHealthIndicator", "jmsHealthContributor" })
|
@ConditionalOnMissingBean(name = { "jmsHealthIndicator", "jmsHealthContributor" })
|
||||||
public HealthContributor jmsHealthContributor(Map<String, ConnectionFactory> connectionFactories) {
|
public HealthContributor jmsHealthContributor(Map<String, ConnectionFactory> connectionFactories) {
|
||||||
|
|
|
@ -45,6 +45,10 @@ import org.springframework.ldap.core.LdapOperations;
|
||||||
public class LdapHealthContributorAutoConfiguration
|
public class LdapHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<LdapHealthIndicator, LdapOperations> {
|
extends CompositeHealthContributorConfiguration<LdapHealthIndicator, LdapOperations> {
|
||||||
|
|
||||||
|
public LdapHealthContributorAutoConfiguration() {
|
||||||
|
super(LdapHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "ldapHealthIndicator", "ldapHealthContributor" })
|
@ConditionalOnMissingBean(name = { "ldapHealthIndicator", "ldapHealthContributor" })
|
||||||
public HealthContributor ldapHealthContributor(Map<String, LdapOperations> ldapOperations) {
|
public HealthContributor ldapHealthContributor(Map<String, LdapOperations> ldapOperations) {
|
||||||
|
|
|
@ -44,6 +44,10 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
public class MailHealthContributorAutoConfiguration
|
public class MailHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<MailHealthIndicator, JavaMailSenderImpl> {
|
extends CompositeHealthContributorConfiguration<MailHealthIndicator, JavaMailSenderImpl> {
|
||||||
|
|
||||||
|
public MailHealthContributorAutoConfiguration() {
|
||||||
|
super(MailHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "mailHealthIndicator", "mailHealthContributor" })
|
@ConditionalOnMissingBean(name = { "mailHealthIndicator", "mailHealthContributor" })
|
||||||
public HealthContributor mailHealthContributor(Map<String, JavaMailSenderImpl> mailSenders) {
|
public HealthContributor mailHealthContributor(Map<String, JavaMailSenderImpl> mailSenders) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,6 +43,10 @@ class Neo4jHealthContributorConfigurations {
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class Neo4jConfiguration extends CompositeHealthContributorConfiguration<Neo4jHealthIndicator, Driver> {
|
static class Neo4jConfiguration extends CompositeHealthContributorConfiguration<Neo4jHealthIndicator, Driver> {
|
||||||
|
|
||||||
|
Neo4jConfiguration() {
|
||||||
|
super(Neo4jHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "neo4jHealthIndicator", "neo4jHealthContributor" })
|
@ConditionalOnMissingBean(name = { "neo4jHealthIndicator", "neo4jHealthContributor" })
|
||||||
HealthContributor neo4jHealthContributor(Map<String, Driver> drivers) {
|
HealthContributor neo4jHealthContributor(Map<String, Driver> drivers) {
|
||||||
|
@ -56,6 +60,10 @@ class Neo4jHealthContributorConfigurations {
|
||||||
static class Neo4jReactiveConfiguration
|
static class Neo4jReactiveConfiguration
|
||||||
extends CompositeReactiveHealthContributorConfiguration<Neo4jReactiveHealthIndicator, Driver> {
|
extends CompositeReactiveHealthContributorConfiguration<Neo4jReactiveHealthIndicator, Driver> {
|
||||||
|
|
||||||
|
Neo4jReactiveConfiguration() {
|
||||||
|
super(Neo4jReactiveHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "neo4jHealthIndicator", "neo4jHealthContributor" })
|
@ConditionalOnMissingBean(name = { "neo4jHealthIndicator", "neo4jHealthContributor" })
|
||||||
ReactiveHealthContributor neo4jHealthContributor(Map<String, Driver> drivers) {
|
ReactiveHealthContributor neo4jHealthContributor(Map<String, Driver> drivers) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class ConnectionFactoryHealthContributorAutoConfiguration
|
||||||
private final Map<String, ConnectionFactory> connectionFactory;
|
private final Map<String, ConnectionFactory> connectionFactory;
|
||||||
|
|
||||||
ConnectionFactoryHealthContributorAutoConfiguration(Map<String, ConnectionFactory> connectionFactory) {
|
ConnectionFactoryHealthContributorAutoConfiguration(Map<String, ConnectionFactory> connectionFactory) {
|
||||||
|
super(ConnectionFactoryHealthIndicator::new);
|
||||||
this.connectionFactory = connectionFactory;
|
this.connectionFactory = connectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.actuate.autoconfigure.health;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfigurationReflectionTests.TestHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.Health.Builder;
|
||||||
|
import org.springframework.boot.actuate.health.HealthContributor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link CompositeHealthContributorConfiguration} using reflection to create
|
||||||
|
* indicator instances.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "3.0.0", forRemoval = true)
|
||||||
|
class CompositeHealthContributorConfigurationReflectionTests
|
||||||
|
extends AbstractCompositeHealthContributorConfigurationTests<HealthContributor, TestHealthIndicator> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractCompositeHealthContributorConfiguration<HealthContributor, TestHealthIndicator, TestBean> newComposite() {
|
||||||
|
return new ReflectiveTestCompositeHealthContributorConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ReflectiveTestCompositeHealthContributorConfiguration
|
||||||
|
extends CompositeHealthContributorConfiguration<TestHealthIndicator, TestBean> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TestHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
||||||
|
TestHealthIndicator(TestBean testBean) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doHealthCheck(Builder builder) throws Exception {
|
||||||
|
builder.up();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -37,6 +37,10 @@ class CompositeHealthContributorConfigurationTests
|
||||||
static class TestCompositeHealthContributorConfiguration
|
static class TestCompositeHealthContributorConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<TestHealthIndicator, TestBean> {
|
extends CompositeHealthContributorConfiguration<TestHealthIndicator, TestBean> {
|
||||||
|
|
||||||
|
TestCompositeHealthContributorConfiguration() {
|
||||||
|
super(TestHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestHealthIndicator extends AbstractHealthIndicator {
|
static class TestHealthIndicator extends AbstractHealthIndicator {
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.actuate.autoconfigure.health;
|
||||||
|
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfigurationReflectionTests.TestReactiveHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.Health;
|
||||||
|
import org.springframework.boot.actuate.health.Health.Builder;
|
||||||
|
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link CompositeReactiveHealthContributorConfiguration} using reflection to
|
||||||
|
* create indicator instances.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "3.0.0", forRemoval = true)
|
||||||
|
class CompositeReactiveHealthContributorConfigurationReflectionTests extends
|
||||||
|
AbstractCompositeHealthContributorConfigurationTests<ReactiveHealthContributor, TestReactiveHealthIndicator> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractCompositeHealthContributorConfiguration<ReactiveHealthContributor, TestReactiveHealthIndicator, TestBean> newComposite() {
|
||||||
|
return new TestCompositeReactiveHealthContributorConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TestCompositeReactiveHealthContributorConfiguration
|
||||||
|
extends CompositeReactiveHealthContributorConfiguration<TestReactiveHealthIndicator, TestBean> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TestReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
|
||||||
|
|
||||||
|
TestReactiveHealthIndicator(TestBean testBean) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Mono<Health> doHealthCheck(Builder builder) {
|
||||||
|
return Mono.just(builder.up().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -40,6 +40,10 @@ class CompositeReactiveHealthContributorConfigurationTests extends
|
||||||
static class TestCompositeReactiveHealthContributorConfiguration
|
static class TestCompositeReactiveHealthContributorConfiguration
|
||||||
extends CompositeReactiveHealthContributorConfiguration<TestReactiveHealthIndicator, TestBean> {
|
extends CompositeReactiveHealthContributorConfiguration<TestReactiveHealthIndicator, TestBean> {
|
||||||
|
|
||||||
|
TestCompositeReactiveHealthContributorConfiguration() {
|
||||||
|
super(TestReactiveHealthIndicator::new);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
|
static class TestReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
|
||||||
|
|
Loading…
Reference in New Issue