SpringBoot整合Druid报错解决:The server time zone value '�й���׼ʱ��' is unrecognized or represents.........

1、SpringBoot 整合Druid

参考文章:Druid(新版starter)在SpringBoot下的使用

2、报错解决

2.1、报错A

2.1.1、报错信息

The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

大体意思就是:

服务器时区值’�й������’无法识别或代表多个时区。 如果要使用时区支持,则必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值。

2.1.2、解决方案

网上大部分的解决方案为在MySQL的URL后面加上?serverTimezone=UTC
但我添加上之后还是依旧报这个错误。
最终参考文章mysql时区问题设置才解决了这个问题。
即解决方案:
在可执行sql环境执行如下sql:

#全局设置时区为东8区,即北京时间
SET GLOBAL time_zone = '+8:00';
或
#仅修改当前会话时区 
SET time_zone = '+8:00';
#立即生效修改
FLUSH PRIVILEGES;

2.2、报错B

2.2.1、报错信息

Error creating bean with name ‘dataSource’ defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]
Caused by: java.lang.IllegalAccessError: class com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper$$EnhancerBySpringCGLIB$$d6716674 cannot access its superclass com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper

2.2.2、报错原因

DruidDataSourceAutoConfigure会注入一个DataSourceWrapper,其会在原生的spring.datasource下找url,username,password等。而我们动态数据源的配置路径是变化的。

2.2.2、解决方案

启动类添加(exclude = DruidDataSourceAutoConfigure.class)即

@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值