无法在 spring-servlet.xml 文件中创建 org.apache.commons.dbcp.BasicDa



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

例外是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

<dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
</dependency>

相关内容

最新更新