2016-07-22 120 views
0

我在Spring Boot 1.3.6中使用自動配置的DataSource,並且使用Actuator的健康端點。但是,運行狀況端點不包括輸出中的任何數據庫組件。Spring Boot Actuator DataSourceHealthIndicator不適用於自動配置的DataSource

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 

從/健康端點的輸出是:

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

我啓用跟蹤日誌記錄,它看起來像春天開機自動配置前的衛生指標數據源。下面是來自跟蹤日誌的摘錄(注意時間戳):

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() 

我做得不對,或者這是春天啓動的錯誤嗎?有沒有辦法改變順序,以便數據源首先被初始化?

回答

0

我的問題是由從Eclipse運行應用程序引起的。我在src/test/java中也有一個TestApplication類,它排除了DataSourceAutoConfiguration。我從組件掃描中排除TestApplication類(通過excludeFilter,@ComponentScan),並且健康端點按預期工作(即它包括數據庫信息)。

相關問題