Spring Boot Actuator DataSourceHealthIndicator不适用于自动配置的DataSource

时间:2016-07-22 00:19:02

标签: spring-boot spring-boot-actuator

我在Spring Boot 1.3.6中使用自动配置的DataSource,而我正在使用Actuator的健康端点。但是,运行状况端点不包括输出中的任何数据库组件。

我的application.properties如下:

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:local
spring.datasource.username=vagrant
spring.datasource.password=vagrant
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

endpoints.enabled=false
endpoints.health.enabled=true

/ health端点的输出是:

{"status":"UP","diskSpace":{"status":"UP","total":499863515136,"free":121851781120,"threshold":10485760}}

我启用了跟踪日志记录,看起来Spring Boot会在数据源之前自动配置运行状况指示器。以下是跟踪日志的摘录(请注意时间戳):

2016-07-22 10:07:20.976 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnClassCondition       : Condition OnClassCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration matched due to @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate
2016-07-22 10:07:20.977 TRACE 7628 --- [restartedMain] .b.a.a.OnEnabledHealthIndicatorCondition : Condition OnEnabledHealthIndicatorCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration matched due to All default health indicators are enabled by default
2016-07-22 10:07:23.304 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnClassCondition       : Condition OnClassCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration matched due to @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate
2016-07-22 10:07:23.305 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnBeanCondition        : Condition OnBeanCondition on org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration$DataSourcesHealthIndicatorConfiguration did not match due to @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found no beans

2016-07-22 10:07:23.577 TRACE 7628 --- [restartedMain] o.s.b.a.condition.OnBeanCondition        : Condition OnBeanCondition on org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration matched due to @ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) found no beans
2016-07-22 10:07:23.578 DEBUG 7628 --- [restartedMain] a.ConfigurationClassBeanDefinitionReader : Registered bean definition for imported class 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration'
2016-07-22 10:07:23.578 DEBUG 7628 --- [restartedMain] a.ConfigurationClassBeanDefinitionReader : Registering bean definition for @Bean method org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()

我做错了什么,或者这是Spring Boot中的错误?有没有办法改变顺序,以便首先初始化数据源?

1 个答案:

答案 0 :(得分:0)

我的问题是由Eclipse运行应用程序引起的。我在src / test / java中也有一个TestApplication类,它排除了DataSourceAutoConfiguration。我从组件扫描中排除了TestApplication类(通过excludeFilter上的@ComponentScan),健康端点按预期工作(即包含数据库信息)。