问题描述
<!--启动包扫描功能--><context:component-scanbase-package="cn.jugame.*"></context:component-scan><beanid="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><propertyname="locations"><list><value>classpath:resources.properties</value></list></property></bean><!--数据库配置--><beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"><propertyname="driverClass"value="${connection.driver_class}"/><propertyname="jdbcUrl"value="${connection.url}"/><propertyname="user"value="${connection.username}"/><propertyname="password"value="${connection.password}"/><propertyname="maxIdleTime"value="${conn.maxIdleTime}"/><propertyname="maxStatements"value="${conn.maxStatements}"/><propertyname="initialPoolSize"value="${conn.initialPoolSize}"/><propertyname="maxPoolSize"value="${conn.maxPoolSize}"/><propertyname="minPoolSize"value="${conn.minPoolSize}"/></bean><beanid="springFactory"class="cn.jugame.util.SpringFactory"/><!--ibatis的sqlMapClient--><beanid="sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><propertyname="configLocation"value="classpath:sql-map-config.xml"/><propertyname="dataSource"ref="dataSource"/></bean><beanid="drawRecordDao"class="cn.jugame.draw.dao.DrawRecordDao"><propertyname="sqlMapClient"ref="sqlMapClient"/></bean>
解决方案
解决方案二:
加上这个试试,然后dao里用sqlSession<beanid="sqlSession"class="org.mybatis.spring.SqlSessionTemplate"><constructor-argindex="0"ref="sqlMapClient"/></bean>
解决方案三:
<!--引入jdbc配置文件--><context:property-placeholderlocation="classpath:dataSource.properties"/><!--创建jdbc数据源--><beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><propertyname="driverClassName"value="${driver}"/><propertyname="url"value="${url}"/><propertyname="username"value="${username}"/><propertyname="password"value="${password}"/></bean><!--(事务管理)transactionmanager,useJtaTransactionManagerforglobaltx--><beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><propertyname="dataSource"ref="dataSource"/></bean><!--创建SqlSessionFactory,同时指定数据源--><beanid="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><propertyname="configLocation"><value>classpath:com/md/sqlmapper/sqlMapConfig.xml</value></property></bean><beanid="sqlSession"class="org.mybatis.spring.SqlSessionTemplate"><constructor-argindex="0"ref="sqlSessionFactory"/></bean><!--注入SqlSessionTemplate实例--><beanid="baseDaoImpl"class="com.md.dao.impl.BaseDaoImpl"><propertyname="sqlSessionTemplate"ref="sqlSession"/></bean><!--可通过注解控制事务--><tx:annotation-driven/><!--Mapper接口所在包名,Spring会自动查找其下的MapperMapperScanner配置.自动去搜索mapper里的对象,并注入.--><beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer"><propertyname="basePackage"value="com.md.dao.*"/></bean>