Communications link failure , Spring Boot + MySql +Docker + Hibernate(通信链路故障,Spring Boot + MySql +Docker + Hibernate)
问题描述
我正在使用 spring boot、hibernate &数据库.在运行应用程序时,它按预期运行良好.但是在制作 docker-compose 文件并使用 mysql docker 镜像运行应用程序 docker 镜像时,它会出现此错误.
<块引用>错误com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败java.net.ConnectException: 连接被拒绝.
<块引用>
Application.properties
spring.datasource.url=jdbc:mysql://localhost/database?autoReconnect=true&useSSL=falsespring.datasource.username=root
spring.datasource.password=root
请指导我如何解决这个问题.
问题是由于在 jdbc url 中引用了 localhost.
以下配置应该可以工作.
I'm working with spring boot, hibernate & MySql. While running the application it is running well as per expectation . But while making the docker-compose file and running the app docker image with mysql docker image it gives this error.
Error com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure java.net.ConnectException: Connection refused.
Application.properties
spring.datasource.url=jdbc:mysql://localhost/database?autoReconnect=true&useSSL=false spring.datasource.username=root
spring.datasource.password=root
Please guide me how to tackle this.
Issue is due to reference of localhost in the jdbc url.
Below configuration should work.
这篇关于通信链路故障,Spring Boot + MySql +Docker + Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!