Spring 3.2 integrates data source with mybatis error

The configuration file is as follows:
<context:property-placeholder location="classpath*:conf/jdbc.properties" />
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="${dba.jdbc.driverClassName}" />
        <property name="url" value="${dba.jdbc.url}" />
        <property name="username" value="${dba.jdbc.username}" />
        <property name="password" value="${dba.jdbc.password}" />
	</bean>
	
	<!--Transactions-->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager" />
	
	<!-- 配置SqlSessionFactoryBean -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
	    <property name="mapperLocations" >
	    	<list>
	    		<value>classpath*:com/cnnct/product/jftcardcs/dao/*.xml"</value>
	    		<value>classpath*:com/cnnct/system/dao/*.xml"</value>
	    	</list>
	    </property>
	</bean>
	<!-- scan for mappers and let them be autowired -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.cnnct.product.jftcardcs.dao,com.cnnct.Base" />
		
	</bean>

The following error occurs when starting up
java.lang.IllegalStateException: Could not load JDBC driver class [${dba.jdbc.driverClassName}]

If it is directly modified to non-${} mode, everything is normal. It is said on the

 Internet that when org.mybatis.spring.mapper.MapperScannerConfigurer is used for automatic scanning in spring, if sqlSessionFactory is set, it may cause PropertyPlaceholderConfigurer to fail, that is, use ${jdbc Expressions such as .username} will not be able to get the contents of the properties file. The reason for this is that MapperScannerConigurer is actually in the stage 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 string copy. 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 define MapperFactoryBean directly, or give up the automatic proxy interface method.
So the configuration file was modified to solve the problem
<!-- 配置SqlSessionFactoryBean -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
	    <property name="mapperLocations" >
	    	<list>
	    		<value>classpath*:com/cnnct/product/jftcardcs/dao/*.xml"</value>
	    		<value>classpath*:com/cnnct/system/dao/*.xml"</value>
	    	</list>
	    </property>
	</bean>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326897755&siteId=291194637