ssm整合报错(一)
今天ssm整合报错:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'lenovo'@'localhost' (using password: YES)
### The error may exist in com/wang/mapper/BookMapper.xml
### The error may involve com.wang.mapper.BookMapper.addBook
### The error occurred while executing an update
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'lenovo'@'localhost' (using password: YES)
找了各种解决方法,检查了一下午加一晚上,终于在刚刚看到一位大佬博客 jelly54 ,找出来了,原来db.properties文件里,username要改为jdbc.username。
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/summer01?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
jdbc.username=root
jdbc.password=18170021
原因:org.springframework.core.env.PropertySourcesPropertyResolver,这个类会去加载你的各项属性,但是他先会去你的环境属性去寻找,再去系统属性去寻找,然后再去系统环境去寻找,如果这期间找到了与property 标签里的name相匹配的key则不继续寻找直接return,否则 return null,并在本地properties开始寻找。。。这就明了了。。原来我的本地系统用户名,username与property 标签里的name一样,被抓取出来了,都没执行到本地的db.properties文件。
for user 'lenovo'@'localhost' (using password: YES)
user并不是localhost而是 lenovo@localhost
再一次感谢大佬jelly54

浙公网安备 33010602011771号