下面的错误应该是与数据源的注入相关吧!!!但是为什么引入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/150
提交
取消