Error creating bean with name ‘sqlSessionFactory‘ 、MySQL启动报错

今天学习SpringSecurity的时候,选用了springboot,因为公司用的不是boot,所以,boot一直不是很熟悉,在此连接数据库的时候,遇到了一个bug。

 

 

Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: GlobalConfigUtils setMetaData Fail !  Cause:java.sql.SQLException: 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.

翻译过来就是

创建类路径资源[com/baumidou/mybatisplus/autoconfig/MybatisPlusAutoConfiguration.class]中定义的名为“sqlSessionFactory”的bean时出错:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans。BeanInstanceException:未能实例化[org.apache.ibatis.session.SqlSessionFactory]:工厂方法“SqlSessionFactory”引发了异常;嵌套异常是com.baomidou.mybatisplus.core.exeptions。MybatisPlusException:错误:GlobalConfigUtils setMetaData失败!原因:java.sql。SQLException:服务器时区值'�й���׼ʱ��' 无法识别或表示多个时区。如果要使用时区支持,必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性),以使用更具体的时区值。

我用的相关依赖是

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--spring-security依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!--mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>


        <!--junit单元测试-->

        <!--MySQL的驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!--lombok 用来简化实体类-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>


    </dependencies>

我的配置文件是

#spring:
#  security:
#    user:
#      name: zlf
#      password: 666
#    driver-class-name: com.mysql.cj.jdbc.Driver
#    url: jdbc:mysql://localhost:3306/mybatis_plus?characterEncoding=utf-8&useSSL=false
#    username: root
#    password: 
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springsecurity?serverTimezone=GMT%2B8
    username: root
    password: 

 我本地装的MySQL版本是5.5+的,一开始没想到时区的事情,之前做demo的时候,也没有因为时区报错,这次报错让我不明所以,我就试着加上时区操作了,结果成了

分析我错误的原因是,采用的依赖是8.0+版本的MySQL,但是没有采用HikariDataSourc数据源,也没有加时区,所以报错了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
WARN 13352 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.bean s.factory.UnsatisfiedDependencyException: Error creating bean with name 'caseController': Unsatisfied dependency expressed through field 'caseService'; nested exception is org.springframework.beans.factory.U nsatisfiedDependencyException: Error creating bean with name 'caseServiceImpl': Unsatisfied dependency expressed through field 'caseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedD ependencyException: Error creating bean with name 'caseMapper' defined in URL [jar:file:/D:/demo/Jiye/target/Jiye-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/upc/jiye/dao/CaseMapper.class]: Unsatisfied depende ncy expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in cla ss path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframewo rk.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Generic.class]: Bean ins tantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver
07-09
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值