spring-4.2.5 hibernate-5.1.0
spring整合hibernate时想使用spring提供的sessionfactory遇到下面的异常:
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'myDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
在网上搜了一下,都是说缺少了commons-dbcp和commons-pool这两个包,我都加到lib目录下之后问题依然存在,求解?
以下是spring的配置,copy官方文档的
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/myssh"/>
<property name="username" value="yujf"/>
<property name="password" value="yujf1992"/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="mappingResources">
<list>
<value>User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>
很明显是少了commons-dbcp和commons-pool这两个包。
你只是copy到lib下,有没有build path-->add to build path?