springboot 配置多源数据库问题。
测试了一下springboot配置多源数据库,mysql和postgresql,yml配置如下:
spring:
datasource:
dynamic:
primary: mysql
strict: false
datasource:
mysql:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
url: jdbc:mysql://*.*.*.*:3306/student?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
postgresql:
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: weixj5217
driverClassName: org.postgresql.Driver
运行程序,出现如下错误:
……
9:30:59:048] [INFO] - org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.prepareWebApplicationContext(ServletWebServerApplicationContext.java:292) - Root WebApplicationContext: initialization completed in 1080 ms
[19:30:59:138] [INFO] - com.zaxxer.hikari.HikariDataSource.(HikariDataSource.java:80) - mysql - Starting...
[19:31:21:237] [ERROR] - com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:594) - mysql - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:448) ~[mysql-connector-java-8.0.29.jar:8.0.29]
……
从错误中看,好像mysql启动错误。
说明一下:
单独连接mysql数据库(不是多源数据库),程序正常,不会出现上面的错误。
多次修改yml配置,还是不行。
先检查有没有依赖
有的话需要贴完整错误信息