我正在尝试使用Hibernate Core 4.1.7和Spring 3.1.2的简单Hibernate分片示例(是的,奇怪的,3.0.0.Beta2于4年前发布),并在会话工厂初始化期间遇到了这个问题:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [shardedspring-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory it.sella.lab.crm.sys.persistence.ShardedSessionFactoryBuilder.createSessionFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at in.rixx.crm.model.Activity.<clinit>(Activity.java:17)
这是我选择Spring和Hibernate的方式:
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.7.Final</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.2.RELEASE</version> </dependency>
这似乎不是碎片库的问题- 看起来是由重构的SessionFactoryImplementor类引起的一般问题。参考https://jira.springsource.org/browse/SPR-8885,我还切换到了Bean’transactionmanager’的org.springframework.orm.hibernate4.HibernateTransactionManager- 它没有帮助。
Spring 3.x和Hibernate 4.x现在有任何功能性变通办法吗?
我看到您正在使用带有弹簧的HIbernate 4。因此,似乎是Spring和Hibernate的相互兼容性问题。因此,请访问以下站点以了解Hibernate 4与Spring的兼容性。
http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and- hibernate-4-1/
否则,请尝试以下版本。
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.3.1.GA</version> </dependency>