r2dbc-mysql 使用的一些问题

文章目录

  • 1. timezone 警告
  • 2. dev.miku.r2dbc-mysql 与 spring-boot-starter-parent 兼容性问题


1. timezone 警告

  • application.yml 相关配置:
#
spring:
  application:
    name: xxx
  r2dbc:
    url: r2dbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai
...
  • 控制台警告内容如下:
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is <?й???׼ʱ?> that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is  that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is <?й???׼ʱ?> that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is  that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is <?й???׼ʱ?> that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is  that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is <?й???׼ʱ?> that's unknown, trying to use system default timezone
[actor-tcp-nio-1] dev.miku.r2dbc.mysql.MySqlConnection     : The server timezone is  that's unknown, trying to use system default timezone
  • 如上: 虽然已经配置了 timezone ,但仍然有警告。
  • 经查询 官方(https://github.com/mirromutth/r2dbc-mysql)说明,timezone 相关配置如下:

r2dbc-mysql 使用的一些问题_第1张图片

  • 也就是需要将 application.yml 相关配置 修改为如下:
#
spring:
  application:
    name: xxx
  r2dbc:
    url: r2dbc:mysql://localhost:3306/test?serverZoneId=Asia/Shanghai
...
  • 修改后实测不报警告了:

r2dbc-mysql 使用的一些问题_第2张图片

2. dev.miku.r2dbc-mysql 与 spring-boot-starter-parent 兼容性问题

  • 当 pom.xml 相关配置如下时(r2dbc-mysql 不指定具体版本号):
<parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>
    
    <version>2.6.1version>
    
parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starterartifactId>
    dependency>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-data-r2dbcartifactId>
    dependency>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webfluxartifactId>
    dependency>
    <dependency>
        <groupId>dev.mikugroupId>
        <artifactId>r2dbc-mysqlartifactId>
        <scope>runtimescope>
    dependency>

    
    <dependency>
        <groupId>mysqlgroupId>
        <artifactId>mysql-connector-javaartifactId>
        <scope>runtimescope>
    dependency>
    
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-testartifactId>
        <scope>testscope>
    dependency>
    <dependency>
        <groupId>io.projectreactorgroupId>
        <artifactId>reactor-testartifactId>
        <scope>testscope>
    dependency>
dependencies>
  • 使用 2.7.10 或者 3.xx 时不会引入 r2dbc-mysql,mysql-connector-java也就是说 spring-boot-starter-parent 没有在 中定义相关的版本;
  • 实测 使用 2.6.1 或者 2.3.7.RELEASE 可以引入 r2dbc-mysql,mysql-connector-java 这两个依赖;

以下为猜测

  • 个人猜测高版本可能要用 dev.miku.r2dbc-mysql 的继任者 io.asyncer.r2dbc-mysql 但是到目前为止 maven 中央仓库还没有 io.asyncer.r2dbc-mysql: 1.0.0 但是有另外一个 :
<dependency>
  <groupId>com.github.jasync-sqlgroupId>
  <artifactId>jasync-mysqlartifactId>
  <version>2.1.16version>
dependency>
  • 我不知它们3者什么关系,我也没细看文档,以上都是瞎猜的。

你可能感兴趣的:(java,mysql,数据库,java)