我想在Springboot应用程序中使用application.yml
中的2个不同架构/数据库名称的JDBC URL。
我通过以下参考链接尝试了这些,但不幸的是我无法使此工作。
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)
它是一个旧线程,我不知道您是否为您解决了解决方案。
,但我处在类似的情况下,下面的JDBC URL对我来说像魅力
"jdbc:mysql://IP1:port1,IP2:port2/CommonDbName?failOverReadOnly=false"
在任何时间点,您的应用程序将仅连接到IP1上的一个DB,一旦DB降低,它将切换到第二个dB,即IP2,并且由于您已将failOverReadOnly
标记为False,第二个数据库将在两个读/写模式下都处于活动状态。
参考 -
8.1配置服务器故障转移
我猜,错误消息非常简单 - 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.
您的属性值-failOverReadOnly
被视为-false,address=(type=master)(protocol=tcp)(host=localhost)(port=3306)(user=test)(password=test)/dbname2?failOverReadOnly=false
而不是简单的false
。
格式 -
jdbc:mysql://address=(key1=value)[(key2=value)]...[,address=(key3=value)[(key4=value)]...]...[/[database]]»
[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
指定要首先列出所有address
,然后在一个地址之后写属性时,最后所有属性。
总的来说,您的URL并未以文档中提到的格式。
希望它有帮助!