Spring连接mysql数据库错误:Cannot load JDBC driver class '${driver}'
生活随笔
收集整理的這篇文章主要介紹了
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}'的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鸭心的功效与作用、禁忌和食用方法
- 下一篇: 羊油的功效与作用、禁忌和食用方法