在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ Spring與MyBatis集成,使用的數(shù)據(jù)源是c3p0,為什么需要引入spri

Spring與MyBatis集成,使用的數(shù)據(jù)源是c3p0,為什么需要引入spring-jdbc這個(gè)jar包?(如下面的代碼)

下面的錯(cuò)誤應(yīng)該是與數(shù)據(jù)源的注入相關(guān)吧!!!但是為什么引入spring-jdbc這個(gè)jar包就能解決呢?

如果不引入spring-jdbc這個(gè)jar包:將報(bào)如下的錯(cuò)(關(guān)鍵信息):
警告: Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in file 
[C:\Users\123\IdeaProjects\SpringDemo\target\seckill\WEB-INF\classes\spring\spring-dao.xml]:
 Error setting property values;
 nested exception is org.springframework.beans.PropertyBatchUpdateException; 
nested PropertyAccessExceptions (1) are:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
 Property 'dataSource' threw exception; 
nested exception is java.lang.NoClassDefFoundError: 
org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy

下面再附上spring-dao.xml中有關(guān)數(shù)據(jù)源的配置:

<!--2.數(shù)據(jù)庫(kù)連接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <!--配置連接池屬性-->
    <property name="driverClass" value="${driver}" />

    <!-- 基本屬性 url、user、password -->
    <property name="jdbcUrl" value="${url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${password}" />

    <!--c3p0私有屬性-->
    <property name="maxPoolSize" value="30"/>
    <property name="minPoolSize" value="10"/>
    <!--關(guān)閉連接后不自動(dòng)commit-->
    <property name="autoCommitOnClose" value="false"/>

    <!--獲取連接超時(shí)時(shí)間-->
    <property name="checkoutTimeout" value="1000"/>
    <!--當(dāng)獲取連接失敗重試次數(shù)-->
    <property name="acquireRetryAttempts" value="2"/>
</bean>



<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!--掃描sql配置文件:mapper需要的xml文件-->
    <property name="mapperLocations" value="classpath:com/imooc/mappers/*.xml"/>
</bean>

回答
編輯回答
筱饞貓

和c3p0沒(méi)有關(guān)系,是因?yàn)閛rg.mybatis.spring.SqlSessionFactoryBean用到了spring-jdbc。

2017年10月13日 05:18