spring+mybatis整合,org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${jdbc.driverClassName}

In using spring + occur Can not load JDBC driver class $ {jdbc.driverClassName} mybatis in wrong time.

 The reason is that the use of org.mybatis.spring.mapper.MapperScannerConfigurer in the spring in the automatic scan when set sqlSessionFactory, it may lead to PropertyPlaceholderConfigurer failure, it is to use $ {jdbc.username} expressions such like, will not to get properties file content. The reason is because that led to this, MapperScannerConigurer actually load bean definitions in the analysis stage, this time if the set sqlSessionFactory, it will lead to initialize some classes ahead of time, this time, PropertyPlaceholderConfigurer not had time to replace the definition of variables, resulting in the expression when for string copy. But if you do not set sqlSessionFactory property, then it must ensure that the name must be a sqlSessionFactory sessionFactory in the spring, otherwise it can not automatically injected. Or directly define MapperFactoryBean, then, or give up the automatic proxy interfaces. 

Solution:

<property name="sqlSessionFactory" ref="ysSqlSessionFactory"></property> 

改成<property name="sqlSessionFactoryBeanName" value="ysSqlSessionFactory" />

 

Reprinted: https: //blog.csdn.net/downkang/article/details/17710259

Guess you like

Origin www.cnblogs.com/xh--/p/11184098.html