Spring连接mysql数据库错误:Cannot load JDBC driver class '${driver}'
2016-03-05 20:46
369 查看
在用Spring使用连接mysql数据库时出现如下错误:
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception isjava.sql.SQLException:
Cannot load JDBC driver class '${driver}'
错误详细信息如下:
原因是因为配置了applicationContext配置文件配置了default-autowire="byName"属性,这样会导致提前初始化一些类,这个时候,PropertyPlaceholderConfigurer还没来得及替换定义中的变量,导致把表达式当作字符串复制了。
解决方案就是删掉这个配置属性即可。
参考资料:
http://songjianyong.iteye.com/blog/1663170 http://www.oschina.net/question/188964_32305
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
相关文章推荐
- JAVA常用基础知识点[继承,抽象,接口,静态,枚举,反射,泛型,多线程...]
- 安装JDK,window下为什么要设置环境变量JAVA_HOME、CLASSPATH、PATH??
- Spring进阶之路(6)-抽象Bean与工厂Bean以及获取Bean的id
- java特种兵读书笔记(5-8)——其他并发编程知识
- java类的初始化顺序
- Spring集成Mybatis配置映射文件方法详解
- LRU缓存算法Java实现
- # 20145205 《Java程序设计》第1周学习总结
- java中的集合
- 20145330孙文馨 《Java程序设计》第一周学习总结
- 20145223《Java程序程序设计》第1周学习总结
- javaweb笔记全套
- 学习java的一点心得(一)
- 解决myeclipse中没有filter新建功能+点击Customize Perspective 没有反应
- Java——java.text.SimpleDateFormat的用法
- Spring集成Mybatis错误Result Maps collection already contains value for XXX
- java访问权限
- java中equals和==的区别详解
- Java泛型
- java web 性能优化----浏览器优化