日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Spring连接mysql数据库错误:Cannot load JDBC driver class '${driver}'

發布時間:2023/12/4 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring连接mysql数据库错误:Cannot load JDBC driver class '${driver}' 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在用Spring使用連接mysql數據庫時出現如下錯誤:

Cause:?org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception isjava.sql.SQLException: Cannot load JDBC driver class '${driver}'


錯誤詳細信息如下:

Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot load JDBC driver class '${driver}' ### The error may exist in file [/Users/guowei/EclipseProjects/workspace/FrameworkMaven/target/classes/com/guowei/maven/framework/mapping/UserMapper.xml] ### The error may involve com.guowei.maven.framework.dao.UserMapper.getUserById ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot load JDBC driver class '${driver}' at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) at com.sun.proxy.$Proxy7.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:165) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) at com.sun.proxy.$Proxy8.getUserById(Unknown Source) at com.guowei.maven.framework.servlet.Test.main(Test.java:18) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot load JDBC driver class '${driver}' ### The error may exist in file [/Users/guowei/EclipseProjects/workspace/FrameworkMaven/target/classes/com/guowei/maven/framework/mapping/UserMapper.xml] ### The error may involve com.guowei.maven.framework.dao.UserMapper.getUserById ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot load JDBC driver class '${driver}' at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:73) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386)
原因是因為配置了applicationContext配置文件配置了default-autowire="byName"屬性,這樣會導致提前初始化一些類,這個時候,PropertyPlaceholderConfigurer還沒來得及替換定義中的變量,導致把表達式當作字符串復制了。


解決方案就是刪掉這個配置屬性即可。


參考資料:

http://songjianyong.iteye.com/blog/1663170

http://www.oschina.net/question/188964_32305



總結

以上是生活随笔為你收集整理的Spring连接mysql数据库错误:Cannot load JDBC driver class '${driver}'的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。