Org.springframework.transaction.CannotCreateTransactionException:Could not open JDBC Connection for transaction; Nested exception is Org.apache.commons.dbcp.SQLNestedException:Cannot load JDBC driver class ' ${jdbc.driverclassname} '
At Org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin (Datasourcetransactionmanager.java : 240)
At Org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction ( abstractplatformtransactionmanager.java:371)
At org.springframework.test.context.transaction.transactionaltestexecutionlistener$ Transactioncontext.starttransaction (transactionaltestexecutionlistener.java:513)
At Org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction ( transactionaltestexecutionlistener.java:271)
At Org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod ( transactionaltestexecutionlistener.java:164)
At Org.springframework.test.context.TestContextManager.beforeTestMethod (testcontextmanager.java:358)
At Org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate ( runbeforetestmethodcallbacks.java:73)
At Org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate ( RUNAFTERTESTMETHODCALLBACKS.JAVA:83)
At Org.springframework.test.context.junit4.statements.SpringRepeat.evaluate (springrepeat.java:72)
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:231)
At Org.junit.runners.BlockJUnit4ClassRunner.runChild (blockjunit4classrunner.java:47)
At Org.junit.runners.parentrunner$3.run (parentrunner.java:231)
At Org.junit.runners.parentrunner$1.schedule (parentrunner.java:60)
At Org.junit.runners.ParentRunner.runChildren (parentrunner.java:229)
At org.junit.runners.parentrunner.access$000 (parentrunner.java:50)
At Org.junit.runners.parentrunner$2.evaluate (parentrunner.java:222)
At Org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate ( RUNBEFORETESTCLASSCALLBACKS.JAVA:61)
At Org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate ( RUNAFTERTESTCLASSCALLBACKS.JAVA:71)
At Org.junit.runners.ParentRunner.run (parentrunner.java:300)
At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run (springjunit4classrunner.java:174)
At Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (junit4testreference.java:50)
At Org.eclipse.jdt.internal.junit.runner.TestExecution.run (testexecution.java:38)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:467)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:683)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:390)
At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:197)
caused By:org.apache.commons.dbcp.SQLNestedException:Cannot load JDBC driver class ' ${jdbc.driverclassname} '
At Org.apache.commons.dbcp.BasicDataSource.createConnectionFactory (basicdatasource.java:1429)
At Org.apache.commons.dbcp.BasicDataSource.createDataSource (basicdatasource.java:1371)
At Org.apache.commons.dbcp.BasicDataSource.getConnection (basicdatasource.java:1044)
At Org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin (Datasourcetransactionmanager.java : 202)
... More
Caused by:java.lang.ClassNotFoundException: ${jdbc.driverclassname}
At Java.net.urlclassloader$1.run (urlclassloader.java:202)
At java.security.AccessController.doPrivileged (Native Method)
At Java.net.URLClassLoader.findClass (urlclassloader.java:190)
At Java.lang.ClassLoader.loadClass (classloader.java:306)
At Sun.misc.launcher$appclassloader.loadclass (launcher.java:301)
At Java.lang.ClassLoader.loadClass (classloader.java:247)
At Org.apache.commons.dbcp.BasicDataSource.createConnectionFactory (basicdatasource.java:1420)
... More
When using Org.mybatis.spring.mapper.MapperScannerConfigurer for automatic scanning in spring, the sqlsessionfactory is set. May cause Propertyplaceholderconfigurer to fail, that is, an expression such as ${jdbc.username} will not be able to get to the content in the properties file. This is caused by the fact that Mapperscannerconigurer is actually parsing the load bean definition phase, which, if set sqlsessionfactory, causes some classes to be initialized in advance, this time, Propertyplaceholderconfigurer has not had time to replace the variables in the definition, causing the expression to be copied as a string. However, if you do not set the Sqlsessionfactory property, you must ensure that the name Sessionfactory in spring will be sqlsessionfactory, otherwise it will not be automatically injected. or directly define the Mapperfactorybean, or discard the automatic proxy interface mode.
This is the org.mybatis.spring.mapper.MapperScannerConfigurer in the configuration of the bean under the attribute sqlsessionfactory, if configured, remove this attribute, become the following:
XML code
- <Bean class="Org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property value="Com.hyq.showcase.mapper,com.hyq.common.core.mapper"
- name="basepackage" />
- </Bean>
- The above solutions are more general, as configured in version 3.1.1, the following are available:
XML code
- <Bean class="Org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name= "basepackage" value="Com.xxxx.dal.mapper" />
- <property name= "sqlsessionfactorybeanname" value="yssqlsessionfactory" />
- <!--<property name= "sqlsessionfactory" ref= "yssqlsessionfactory" ></property> -
- </Bean>
Using Sqlsessionfactorybeanname injection is no problem (do not use sqlsessionfactory attribute injection, use sqlsessionfactorybeanname injection), Because Sqlsessionfactory is not initialized immediately, the incoming name, not the bean, does not cause an early initialization problem.
The above for reference!
- Citation: http://songjianyong.iteye.com/blog/1663170
Org.apache.commons.dbcp.SQLNestedException:Cannot Load JDBC Driver class