账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Spring与MyBatis集成,使用的数据源是c3p0,为什么需要引入spring-jdbc这个jar包?(如下面的代码)
    28
    0

    下面的错误应该是与数据源的注入相关吧!!!但是为什么引入spring-jdbc这个jar包就能解决呢?

    如果不引入spring-jdbc这个jar包:将报如下的错(关键信息):
    警告: 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中有关数据源的配置:

    <!--2.数据库连接池-->
    <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"/>
        <!--关闭连接后不自动commit-->
        <property name="autoCommitOnClose" value="false"/>
    
        <!--获取连接超时时间-->
        <property name="checkoutTimeout" value="1000"/>
        <!--当获取连接失败重试次数-->
        <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>
    
    
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ぐ花葬つ 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部