2011-10-02 46 views
14

Tôi nhận được ngoại lệ này khi cố gắng khởi động ứng dụng ngủ đông mùa hè MVC của tôi.Không thể tìm thấy lớp [org.apache.commons.dbcp.BasicDataSource]

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring/appServlet/mysql_persistence_info.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource 
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1235) 

My /WEB-INF/spring/appServlet/mysql_persistence_info.xml là

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
    <property name="url" value="jdbc:mysql://localhost/MyrDB"/> 
    <property name="username" value="user"/> 
    <property name="password" value="user"/> 
    <!-- connection pooling details --> 
    <property name="initialSize" value="1"/> 
    <property name="maxActive" value="5"/> 
    </bean> 
    <bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="hibernateProperties"> 
    <props> 
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> 
    <prop key="hibernate.show_sql">true</prop> 
    <prop key="hibernate.hbm2ddl.auto">update</prop> 
    </props> 
    </property> 
    <property name="annotatedClasses"> 
    <list> 
    <!-- all the annotation entity classes --> 
    </list> 
    </property> 
    </bean> 
    </beans> 

tôi có tất cả các file jar cần thiết trong classapath. Tôi đang sử dụng STS.

Tôi có commons-dbcp.jar và tất cả các tệp còn lại của tệp jar.

+2

Nó không đủ để có các lọ trong STS/eclipse classpath - chúng nên ở trong thư mục web-inf \ lib - nếu bạn đang cố gắng chạy nó như là một webapp. – gkamal

+0

Với STS tôi không biết thực sự biết đường dẫn web-inf/lib ở đâu. Tôi đã tìm trong thư mục ứng dụng web và không có thư mục web-inf/lib. – djoshi

Trả lời

21

Hãy đảm bảo rằng tệp commons-dbcp-1.4.jar nằm trong thư mục lib của bạn. bạn nên sao chép qua nó trong nhật thực.

Xem hình ảnh này

enter image description here

+0

Tôi phải thêm common-pools.jar và spring.jar. Ngoài ra tôi đã phải thêm một thư mục web-inf/lib và kéo nó vào. Tôi sẽ nghĩ rằng STS sẽ có tự động tạo ra nhưng nó không có vẻ nó đã làm nó. – djoshi

+0

Tất cả lọ phải có mặt ở đó, nhưng đối với org.apache.commons.dbcp.BasicDataSource câu hỏi của bạn nằm bên trong commons-DBCP-1.x.jar –

+5

Đối với những người sử dụng maven: \t \t commons-DBCP \t \t commons-DBCP \t \t 1,4 \t

0

đã làm một thư mục sạch của tomcat từ nhật thực và nó làm việc mà không cần tải file jar

3

Đối với tôi, chỉ cần thêm commons-DBCP-1.4.jar đến classpath của tôi đã không hoạt động. Đã phải thêm commons-pool-1.6.jar. Điều này post mô tả lý do. Có một liên kết tải xuống trong bài đăng đó.

Các vấn đề liên quan