Springboot遇到的一些问题

数据库MySQL连接问题

  1. 参数配置

    报错:java.sql.SQLException: Access denied for user ‘’@‘localhost’ (using password: NO)

    配置信息

    #用于执行DML脚本的数据库的用户名
    spring.datasource.data-username=root 
    #执行DML脚本的数据库的密码
    spring.datasource.data-password=123
    

    需要修改为

    spring.datasource.username=root
    spring.datasource.password=123
    
  2. 时区问题

    **报错:**You must configure either the server or JDBC driver (via the serverTimezone conf)

    **原因:**使用的数据库是MySQL,从上面图看出SpringBoot2.1在你没有指定MySQL驱动版本的情况下它自动依赖的驱动是8.0.12很高的版本,这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题

    解决办法一

    在url名后增加 ?serverTimezone=UTC

    解决办法二:

    进入数据库,修改时区信息

    mysql -u root -p
    show variables like '%time_zone%';
    set global time_zone = '+8:00' ;
    
    1. 数据库驱动问题

    **报错:**Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

    **原因:**数据库驱动com.mysql.jdbc.Driver’已经被弃用了、应当使用新的驱动com.mysql.cj.jdbc.Driver’

    **解决办法:**yml中的配置修改为:

    driver-class-name: com.mysql.cj.jdbc.Driver
    
    1. 自动注入问题

    报错如下:

    Field employeeService in com.study.cache.controller.EmployeeController required a bean of type 'com.study.cache.service.EmployeeService' that could not be found.
    
    The injection point has the following annotations:
    	- @org.springframework.beans.factory.annotation.Autowired(required=true)
    
    

    原因:

    在service层未添加@Server注解

    另,在Mapper层需要添加@Mapper注解

  3. 驼峰命名匹配规则

mybatis.configuration.map-underscore-to-camel-case=true
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值