1

我是 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>

谢谢。

4

1 回答 1

1

我认为您缺少 .jar 文件org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean。您应该包括其中一个罐子。找到 http://www.jarfinder.com/index.php/java/info/org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

于 2012-09-14T04:09:04.367 回答