【发布时间】:2020-07-04 22:56:00
【问题描述】:
我尝试学习如何使用 docker-compose 将 Spring App 与 MySQL 连接起来。
我遇到了以下问题:
spring-db | 2020-03-24 13:18:50+01:00 [Note] [Entrypoint]: Temporary server started.
spring-db | 2020-03-24T12:18:50.676560Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
spring-db | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
spring-db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
spring-db | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
spring-db | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
spring-db | 2020-03-24 13:18:54+01:00 [Note] [Entrypoint]: Creating database spring-db
spring-db | 2020-03-24 13:18:54+01:00 [Note] [Entrypoint]: Creating user spring-db
spring-db | 2020-03-24 13:18:54+01:00 [Note] [Entrypoint]: Giving user spring-db access to schema spring-db
spring-db |
spring-db | 2020-03-24 13:18:54+01:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/spring-db.sql
spring-db |
spring-db |
spring-db | 2020-03-24 13:18:55+01:00 [Note] [Entrypoint]: Stopping temporary server
spring-db | 2020-03-24T12:18:55.410358Z 15 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
spring-db | 2020-03-24T12:18:57.128567Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
spring-db | 2020-03-24 13:18:57+01:00 [Note] [Entrypoint]: Temporary server stopped
spring-db |
spring-db | 2020-03-24 13:18:57+01:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
因此我收到以下错误:
spring-app | 2020-03-24 12:19:11.993 ERROR 1 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection] with root cause
spring-app |
spring-app | java.net.ConnectException: Connection refused (Connection refused)
有人遇到过类似的问题吗?
提前感谢您的帮助。
【问题讨论】:
-
请在spring中分享docker-compose.yml和数据源配置
-
我今天遇到了一个非常相似的问题。不同之处在于有多个 docker-compose 堆栈具有一个 mysql 容器,并且 docker-compose.yaml 是动态生成的。所以我会看看你的情况,并尝试在我的本地开发人员中复制这个问题。感谢您发布此内容。
标签: mysql spring docker docker-compose