数据库MySQL连接问题
-
参数配置
报错: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
-
时区问题
**报错:**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' ;
**报错:**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.jdbc.Driver’已经被弃用了、应当使用新的驱动com.mysql.cj.jdbc.Driver’
**解决办法:**yml中的配置修改为:
driver-class-name: com.mysql.cj.jdbc.Driver
报错如下:
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注解
-
驼峰命名匹配规则
mybatis.configuration.map-underscore-to-camel-case=true