springboot多数据源配置中的坑

1:关于spring-boot-starter-parent版本与mysql版本
springboot-start-parent 2.0.0 :的mysql-connector-java版本是5.x
    数据库连接可正常配置:
    spring.datasource.bianla.driverClassName = com.mysql.jdbc.Driver
    
springboot-start-parent 2.1.0 :的mysql-connector-java版本是6.x
    跟上面一样配置也行,但是会提示:
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. 
    The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    
    要配置成: com.mysql.cj.jdbc.Driver,并指定时区serverTimezone:
    url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&?useUnicode=true&characterEncoding=utf8&useSSL=false
    参考:https://www.cnblogs.com/liaojie970/p/8916568.html
    
    还有mybatis-generator-core 在版本为1.3.7时,对Mysql6.x 的自动化代码功能会异常,只生成mapper的insert的方法,改成Mysql5.x就正常了。(或者提高mybatis-generator-core的版本号,我还没试过...)
    
2:关于jdbc-url
    在正常配置url时:发生异常
    spring.datasource.bianla.url=...
    异常提示:jdbcUrl is required with driverClassName

    原因参考:
    https://blog.csdn.net/qq_22156459/article/details/80283054

    改成这样配置就正常了:
    spring.datasource.bianla.jdbc-url

猜你喜欢

转载自blog.csdn.net/a1214624851/article/details/83958706