今天遇到一个奇葩的问题,获取jdbc.properties中配置好的属性连接数据库竟然失败了。
不多说,直接上代码。
Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Access denied for user '飞飞'@'localhost' (using password: YES)
经过我检查,发现错误就出现在username属性上,spring竟然把${username)的值解析为我电脑用户名的值了,可想而知,肯定连不上了。只要把jdbc.properties和xml的username改成name就行。
至于我为什么不用${jdbc.username}这种写法呢,那样的话是不是不会出现这种错误了呀。没错,直接这样写是不会出现那种奇葩的问题,可是,会出现这种问题啊。。
Invalid bean definition with name 'dataSource' defined in class path resource [applicationContext.xml]:
Could not resolve placeholder 'jdbc.driverClassName' in value "${jdbc.driverClassName}";
我用的原生的spring的jdbc,我怀疑spring没有把${jdbc.username}解析出来。。
本文记录了一次使用Spring JDBC连接数据库时遇到的奇怪问题:由于Spring将属性文件中的用户名误解析为系统的用户名而导致连接失败。文章详细介绍了问题的排查过程及解决办法。
460

被折叠的 条评论
为什么被折叠?



