spring3+mybatis 使用MapperScannerConfigurer时context:property-placeholder载不进属性
来源:互联网 发布:七区独立袋装弹簧 知乎 编辑:程序博客网 时间:2024/05/12 16:05
在系统启动时,MapperScannerConfigurer会立即加载sqlSessionFactory,这时property-placeholder正在解析jdbc.properties,因此会报错:
java.lang.ClassNotFoundException: ${jdbc.driverClass}
如下:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- <property name="configLocation" value="classpath:mybatis-config.xml" /> --><property name="mapperLocations" value="classpath:com/mobile263/meeting/dao/*.xml" /><property name="dataSource" ref="dataSource" /></bean><!-- <bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean"><property name="mapperInterface" value="com.mobile263.meeting.dao.UserDAO"></property><property name="sqlSessionFactory" ref="sqlSessionFactory"></property></bean> --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" lazy-init="true"> <property name="basePackage" value="com.mobile263.meeting.dao" /> <property name="sqlSessionFactoryBeanName" ref="sqlSessionFactory"></property></bean>
给sqlSessionFactory取一个别名,然后以value的形式加载到org.mybatis.spring.mapper.MapperScannerConfigurer中,就不会立即加载sqlSessionFactory,从而导致读取jdbc.properties失败。
<property name="sqlSessionFactoryBeanName" value="aliasSqlSessionFactory"></property>
配置文件改成:
<bean id="aliasSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- <property name="configLocation" value="classpath:mybatis-config.xml" /> --><property name="mapperLocations" value="classpath:com/mobile263/meeting/dao/*.xml" /><property name="dataSource" ref="dataSource" /></bean><!-- <bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean"><property name="mapperInterface" value="com.mobile263.meeting.dao.UserDAO"></property><property name="sqlSessionFactory" ref="sqlSessionFactory"></property></bean> --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" lazy-init="true"> <property name="basePackage" value="com.mobile263.meeting.dao" /> <property name="sqlSessionFactoryBeanName" value="aliasSqlSessionFactory"></property></bean><!-- 事务管理器配置,单数据源事务 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean>
0 0
- spring3+mybatis 使用MapperScannerConfigurer时context:property-placeholder载不进属性
- spring 和mybatis整合时 使用context:property-placeholder载不进属性 还报org.springframework.beans.factory.BeanCrea
- 使用context:property-placeholder载不进属性原因分析与解决方案
- spring使用context:property-placeholder载不进属性问题
- spring使用context:property-placeholder载不进属性问题
- spring使用context:property-placeholder载不进属性问题
- spring使用context-property-placeholder载不进属性问题
- MapperScannerConfigurer与<context:property-placeholder>加载顺序导致异常解决办法
- spring 使用context:property-placeholder载不进属性 属性加载之前就读取属性变量
- spring3配置文件中的context:property-placeholder/元素
- spring3配置文件中的context:property-placeholder/元素
- spring3配置文件中的context:property-placeholder/元素
- spring3的context:property-placeholder详解
- spring配置文件中的context:property-placeholder属性
- spring配置文件中的context:property-placeholder属性
- spring的context:property-placeholder属性
- spring的context:property-placeholder属性
- spring3以后 <context:property-placeholder>配置资源文件
- 0x7FFFFFFF 是long int的最大值
- 数据库水平切分的实现原理解析——分库,分表,主从,集群,负载均衡器
- Linux文件类型与扩展名
- Markdown+Pandoc→HTML幻灯片速成
- python mysql 插入的数据是字典时,可以直接插入到数据库,不要进行for循环读取每一个字段
- spring3+mybatis 使用MapperScannerConfigurer时context:property-placeholder载不进属性
- Could not find Developer Disk Image (今天更新iOS9.3)
- 计算机是如何启动的?
- opencv3.1+vs2015+win764位配置
- SQLite 相关
- linux文件属性详解
- SEL数据类型的简单知识点——和方法有关
- PHP转换SQLite数据库为MySQL
- Unity3D中uGUI事件系统简述及使用方法总结