Spring MVC and Hibernate configurations

2019-09-14 08:51发布

问题:

I have been struggling with this problem for a few days now. I am building a spring mvc hibernate framework.

I have the following configuration file

Please follow this link for the config file : ConfigurationFile

I am receiving the following error:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean] for bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/hibernateDataAccessContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean

Root cause:

Caused by: java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean

Yes, I do have the spring-aop jar included in the class path. I would appreciate any help. My searches have not been fruitful.


Edit:

Thank you. That issue is solved, however my initial intention of this question was to solve the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/hibernateDataAccessContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

This is why I mentioned that I already have spring-aop in the class path.

回答1:

org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean does not exist.

See the Hibernate Documentation.

From this question.

I think you should use org.springframework.orm.hibernate4.LocalSessionFactoryBean instead of org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

From LocalSessionFactoryBean javadoc:

NOTE: This variant of LocalSessionFactoryBean requires Hibernate 4.0 or higher. It is similar in role to the same-named class in the orm.hibernate3 package. However, in practice, it is closer to AnnotationSessionFactoryBean since its core purpose is to bootstrap a SessionFactory from annotation scanning.