我正在创建一个带有休眠集成的spring-mvc项目。我添加了commons-dbcp 1.4 jar文件,其中包含BasicDataSource.class,但是当我尝试在spring-servlet.xml文件中创建其bean时,仍然出现以下错误:


  异常是java.lang.ClassNotFoundException:
  
  org.apache.commons.dbcp.BasicDataSource


我的spring-servlet.xml文件中的代码:

  <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="work"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"></property>
<property name="order" value="3"></property>
</bean>

<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost/spring"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
<bean id="bean" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="ds"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true></prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory></prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>shops.hbm.xml</value>
<value>users.hbm.xml</value>
<value>vehicle.hbm.xml</value>
</list>
</property>
</bean>
<bean id="dao" class="work.OperationDao">
</bean>
</beans>

最佳答案

请将以下依赖项添加到pom.xml

10-08 03:17