SSM druid连接数据库发生异常:com.alibaba.druid.pool.DruidDataSource error
·

分析:Access denied for user '44401'@'localhost' (using password: YES),这里Mysql连接的用户名为电脑的系统名,不是数据库中的用户名root
原因:在Spring完成注入时是用 "${..}" 方式获取值完成注入的。而通过这种表达式也能直接获取到JVM系统属性。
因为在系统中也有个username属性,这时系统变量覆盖了Properties中的值,这时取得username的值为系统的用户名44401(主机名),密码为properties中的password去查询数据库,此时用户名名和密码并不匹配就会报错。
如配置文件:

解决:将properties中的username加个前缀

运行OK

更多推荐
所有评论(0)