diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java index 5d588c7db7..d4a9ce7a9a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java @@ -58,7 +58,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping; /** * {@link EnableAutoConfiguration Auto-configuration} for common management * {@link Endpoint}s. - * + * * @author Dave Syer * @author Phillip Webb * @author Greg Turnquist diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java index 067aedfe6d..f22d11c8c2 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2012-2014 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. @@ -28,6 +28,7 @@ import org.springframework.boot.actuate.health.RedisHealthIndicator; import org.springframework.boot.actuate.health.SimpleDataSourceHealthIndicator; import org.springframework.boot.actuate.health.VanillaHealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.jdbc.CommonsDataSourceConfiguration; @@ -44,6 +45,8 @@ import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.redis.connection.RedisConnectionFactory; /** + * {@link EnableAutoConfiguration Auto-configuration} for {@link HealthIndicator}s. + * * @author Christian Dupuis * @since 1.1.0 */ @@ -72,14 +75,14 @@ public class HealthIndicatorAutoConfiguration { @ConditionalOnMissingBean(name = "dbHealthIndicator") public HealthIndicator dbHealthIndicator() { if (this.dataSources.size() == 1) { - return new SimpleDataSourceHealthIndicator(this.dataSources.values().iterator() - .next()); + return new SimpleDataSourceHealthIndicator(this.dataSources.values() + .iterator().next()); } CompositeHealthIndicator composite = new CompositeHealthIndicator(); for (Map.Entry entry : this.dataSources.entrySet()) { - composite.addHealthIndicator(entry.getKey(), new SimpleDataSourceHealthIndicator( - entry.getValue())); + composite.addHealthIndicator(entry.getKey(), + new SimpleDataSourceHealthIndicator(entry.getValue())); } return composite; } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java index b680cfb01b..83b52da719 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/HealthEndpoint.java @@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; /** * {@link Endpoint} to expose application health. - * + * * @author Dave Syer * @author Christian Dupuis */ @@ -59,9 +59,9 @@ public class HealthEndpoint extends AbstractEndpoint> { * Turns the bean name into a key that can be used in the map of health information. */ private String getKey(String name) { - int x = name.toLowerCase().indexOf("healthindicator"); - if (x > 0) { - return name.substring(0, x); + int index = name.toLowerCase().indexOf("healthindicator"); + if (index > 0) { + return name.substring(0, index); } return name; } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java index 080602e6c3..1e89500a9c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2012-2014 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. @@ -20,13 +20,14 @@ import java.util.HashMap; import java.util.Map; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.util.Assert; import com.mongodb.CommandResult; /** * Simple implementation of a {@link HealthIndicator} returning status information for * Mongo data stores. - * + * * @author Christian Dupuis * @since 1.1.0 */ @@ -35,6 +36,7 @@ public class MongoHealthIndicator implements HealthIndicator private final MongoTemplate mongoTemplate; public MongoHealthIndicator(MongoTemplate mongoTemplate) { + Assert.notNull(mongoTemplate, "MongoTemplate must not be null"); this.mongoTemplate = mongoTemplate; } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisHealthIndicator.java index fe5e342524..34d408ec2e 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisHealthIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2012-2014 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. @@ -23,11 +23,12 @@ import java.util.Properties; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisConnectionUtils; +import org.springframework.util.Assert; /** * Simple implementation of a {@link HealthIndicator} returning status information for * Redis data stores. - * + * * @author Christian Dupuis * @since 1.1.0 */ @@ -36,6 +37,7 @@ public class RedisHealthIndicator implements HealthIndicator private final RedisConnectionFactory redisConnectionFactory; public RedisHealthIndicator(RedisConnectionFactory connectionFactory) { + Assert.notNull(connectionFactory, "ConnectionFactory must not be null"); this.redisConnectionFactory = connectionFactory; } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java index bd279879e2..b77fa0d4be 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java @@ -43,7 +43,7 @@ import static org.junit.Assert.assertTrue; /** * Tests for {@link EndpointAutoConfiguration}. - * + * * @author Dave Syer * @author Phillip Webb * @author Greg Turnquist diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index 9abc4b39e9..10e282a144 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2012-2014 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. @@ -36,7 +36,7 @@ import static org.junit.Assert.assertEquals; /** * Tests for {@link HealthIndicatorAutoConfiguration}. - * + * * @author Christian Dupuis */ public class HealthIndicatorAutoConfigurationTests { @@ -120,7 +120,7 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); - assertEquals(SimpleDataSourceHealthIndicator.class, beans.values().iterator().next() - .getClass()); + assertEquals(SimpleDataSourceHealthIndicator.class, beans.values().iterator() + .next().getClass()); } -} \ No newline at end of file +} diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java index 7be942a0fd..4cd615b3a1 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java @@ -30,7 +30,7 @@ import static org.junit.Assert.assertThat; /** * Tests for {@link HealthEndpoint}. - * + * * @author Phillip Webb */ public class HealthEndpointTests extends AbstractEndpointTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java index eebf168bff..ba69ef7c9d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2012-2014 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. @@ -38,7 +38,7 @@ import static org.junit.Assert.assertTrue; /** * Tests for {@link MongoHealthIndicator}. - * + * * @author Christian Dupuis */ public class MongoHealthIndicatorTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java index c599920f13..957a0e0a02 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2012-2014 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. @@ -37,7 +37,7 @@ import static org.junit.Assert.assertTrue; /** * Tests for {@link RedisHealthIndicator}. - * + * * @author Christian Dupuis */ public class RedisHealthIndicatorTests { diff --git a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 3a214e2399..80e3c848b7 100644 --- a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -164,8 +164,8 @@ To provide custom health information you can register a Spring bean that impleme Spring Boot provides a {sc-spring-boot-actuator}/health/SimpleDatabaseHealthIndicator.{sc-ext}[`SimpleDatabaseHealthIndicator`] -implementation that attempts a simple database test as well as implementations for -Redis and MongoDB. +implementation that attempts a simple database test as well as implementations for +Redis and MongoDB. Spring Boot adds the `HealthIndicator` instances automatically if beans of type `DataSource`, `MongoTemplate` or `RedisConnectionFactory` are present in the `ApplicationContext`.