更新:添加Maven依赖关系 * 更新:通过添加 Maven依赖关系 解决了该错误*
美好的一天。我有AplicationContext.xml的这一部分
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="namingStrategy"> <ref bean="namingStrategy"/> </property> <property name="mappingResources"> <list> <!--<value>genericdaotest/domain/Person.hbm.xml</value>--> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean>
Maven Dep spring和hibernate
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>2.0.6</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.2.Final</version> </dependency>
但是,当我启动我的应用程序时,它告诉我这个错误
Cannot find class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.LocalSessionFactoryBean
但是我正在使用hibernate4。这是什么魔术?=)我已经尝试过重新部署应用程序,但是结果是一样的
您已经错过了Spring-ORM模块:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.1.1.RELEASE</version> </dependency>
检查软件包列表,其中包含所需的org.springframework.orm.hibernate3软件包和类。
org.springframework.orm.hibernate3
另外,我认为课程是错误的,不是hibernate4.LocalSessionFactoryBean吗?您在使用注释吗?或XML?
hibernate4.LocalSessionFactoryBean