我想在SpringBoot应用程序中使用application.yml
中的2个不同架构/数据库名称的jdbc url。使用2个不同的数据库名称的MySQL JDBC URL故障转移
我尝试了以下Reference Link,但不幸的是我无法得到这个工作。
jdbc:mysql://address=(type=master)(protocol=tcp)(host=IP1)(port=3306)(user=root)(password=root)/dbname1?failOverReadOnly=false,address=(type=master)(protocol=tcp)(host=IP2)(port=3306)(user=test)(password=test)/dbname2?failOverReadOnly=false
jdbc:mysql://address=(type=master)(protocol=tcp)(host=IP1)(port=3306)(user=root)(password=root)(dbname=dbname1)?failOverReadOnly=false,address=(type=master)(protocol=tcp)(host=IP2)(port=3306)(user=test)(password=test)(dbname=dbname2)?failOverReadOnly=false
我收到的错误是在启动应用程序时,因为MySQL连接器无法解析url连接字符串。
2017-02-21 11:37:40.724] log4j - 3060 ERROR [main] --- o.a.t.j.p.ConnectionPool: Unable to create initial connections of pool.
java.sql.SQLException: The connection property 'failOverReadOnly' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'false,address=(type=master)(protocol=tcp)(host=localhost)(port=3306)(user=test)(password=test)/dbname2?failOverReadOnly=false' is not in this set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
是你得到一个错误? –
我在启动服务器时收到错误,连接器分析连接url –
错误消息与您粘贴的代码不匹配。在你的代码中,它表示“user = root”,错误表示“user = test”(以及其他差异)。 –