2016-12-22 62 views
1

我有一個春天啓動JPA申請註冊自己爲一個領事的microService:爲什麼領事嘗試連接到我的數據庫?

@SpringBootApplication 
@EnableDiscoveryClient 
@EnableAutoConfiguration 
public class Bootstrapper { 

    public static void main(String[] args) { 
     SpringApplication.run(Bootstrapper.class, args); 
    } 
} 

我application.yml看起來是這樣的:

spring: 
    datasource: 
    url: jdbc:mysql://localhost:3306/butler_test 
    username: root 
    password: pwd 
    driver-class-name: com.mysql.jdbc.Driver 
    jpa: 
    hibernate: 
     ddl-auto: create 
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect 
    show-sql: false 

spring: 
    cloud: 
    consul: 
     discovery: 
     healthCheckPath: /health 
     healthCheckInterval: 10s 

然而,當領事接觸/health端點,以下SQLException引發我的申請:

「主機'172.17.0.1'不允許連接到此MySQL服務器」。

這是怎麼回事,爲什麼還會有連接嘗試?

回答

0

當你配置一個數據源,健康檢查端點將做一個SELECT 1,以確保到數據庫的連接工作在默認情況下強制數據庫。如果是,它將顯示狀態爲「UP」。由於您所看到的錯誤,你的數據庫配置可能不正確。

您可以通過在性能配置它禁用的數據源健康檢查: management.health.db.enabled=false

如果你想配置檢查,看這裏:Spring Boot Actuator Health Indicator

相關問題