簡體   English   中英

Spring和Hibernate集成類找不到異常

[英]spring and hibernate integration class not found exception

我是Spring的新手,嘗試使用spring進行休眠工作。我嘗試了幾個小時才能完成這項工作,但是每次遇到以下類都沒有發現異常時,我會花很多時間。

> Exception in thread "main"
> org.springframework.beans.factory.CannotLoadBeanClassException: Cannot
> find class
> [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]
> for bean with name 'sessionFactory' defined in class path resource
> [mad/springnhibernate/model/spring.xml]; nested exception is
> java.lang.ClassNotFoundException:
> org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
>   at
> org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262)
>   at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
>   at
> org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331)

其次是我的spring.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: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/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="mad.springnhibernate"/>
    <!-- Initialization for data source -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/springnhibernate" />
        <property name="username" value="root" />
        <property name="password" value="pass" />
    </bean>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="mad.springnhibernate.model" />
        <property name="hibernateProperties">
            <props>
                <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
    </bean>

</beans>

謝謝。

我認為您缺少org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean jar文件。 您應該包括其中一個罐子。 查找http://www.jarfinder.com/index.php/java/info/org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM