Cannot load JDBC driver class ${jdbc.driverClassName}' appears when spring+mybatis

When using spring+mybatis, an error such as Cannot load JDBC driver class ${jdbc.driverClassName} will occur.

 The reason is that when org.mybatis.spring.mapper.MapperScannerConfigurer is used for automatic scanning in spring, if sqlSessionFactory is set, it may cause the PropertyPlaceholderConfigurer to fail, that is, using expressions like ${jdbc.username} will fail Get the content in the properties file. The reason for this is because the MapperScannerConigurer is actually in the phase of parsing and loading bean definitions. If sqlSessionFactory is set at this time, it will cause some classes to be initialized in advance. At this time, PropertyPlaceholderConfigurer has not had time to replace the variables in the definition, resulting in the expression as Make a copy of the string. But if you do not set the sqlSessionFactory property, you must ensure that the name of the sessionFactory in spring must be sqlSessionFactory, otherwise it will not be automatically injected. Or directly define MapperFactoryBean, or give up the automatic proxy interface method. 

Solution: change

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

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

The original text is reprinted: http://blog.csdn.net/bell2008/article/details/40712215
ps: In the course of the project, I also encountered the phenomenon of duplicate values ​​in the map value returned by mybatis. The solution is to change the higher version of mybatis The jar package will do.

Guess you like

Origin blog.csdn.net/zhaoxiangpeng16/article/details/51025657