I have a Spring Boot JPA application registering itself as a microservice with Consul:
@SpringBootApplication
@EnableDiscoveryClient
@EnableAutoConfiguration
public class Bootstrapper {
public static void main(String[] args) {
SpringApplication.run(Bootstrapper.class, args);
}
}
My application.yml looks like this:
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
However, when Consul contacts the /health
endpoint, the following SQLException
is thrown in my application:
"Host '172.17.0.1' is not allowed to connect to this MySQL server".
What is going on and why is there even a connection attempt?
When you have a datasource configured, the health check endpoint will ping the database by default by doing a SELECT 1
to make sure the connection to the database is working. If it is, it will display the status as "UP". Since you are seeing the error, your database configuration is probably incorrect.
You can disable the datasource health check by configuring it in your properties:
management.health.db.enabled=false
If you would like to configure the check, see here: Spring Boot Actuator Health Indicator