我使用了相同的代码。但是我收到以下错误。
警告:在上下文初始化期间遇到异常 - 取消刷新尝试: org.springframework.beans.factory.BeanCreationException:创建名称为' myDBAuthenticationService'的注册自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.o7planning.springmvcshoppingcart.dao.AccountDAO org.o7planning.springmvcshoppingcart.authentication.MyDBAuthenticationService.accountDAO;嵌套异常是org.springframework.beans.factory.BeanCreationException:使用名称' accountDAO'创建bean时出错:注册自动装配的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.hibernate.SessionFactory org.o7planning.springmvcshoppingcart.dao.impl.AccountDAOImpl.sessionFactory;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' sessionFactory'的bean时出错在org.o7planning.springmvcshoppingcart.config.ApplicationContextConfig中定义:通过工厂方法的Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.hibernate.SessionFactory]:工厂方法' getSessionFactory'抛出异常;嵌套异常是java.lang.NoSuchMethodError:org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.applyClassLoader(Ljava / lang / ClassLoader;)Lorg / hibernate / boot / registry / BootstrapServiceRegistryBuilder; 2017年5月7日下午12:31:59 org.springframework.web.context.ContextLoader initWebApplicationContext 严重:上下文初始化失败 org.springframework.beans.factory.BeanCreationException:使用名称' myDBAuthenticationService'创建bean时出错:注册自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.o7planning.springmvcshoppingcart.dao.AccountDAO org.o7planning.springmvcshoppingcart.authentication.MyDBAuthenticationService.accountDAO;嵌套异常是org.springframework.beans.factory.BeanCreationException:使用名称' accountDAO'创建bean时出错:注册自动装配的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.hibernate.SessionFactory org.o7planning.springmvcshoppingcart.dao.impl.AccountDAOImpl.sessionFactory;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' sessionFactory'的bean时出错在org.o7planning.springmvcshoppingcart.config.ApplicationContextConfig中定义:通过工厂方法的Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.hibernate.SessionFactory]:工厂方法' getSessionFactory'抛出异常;嵌套异常是java.lang.NoSuchMethodError:org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.applyClassLoader(Ljava / lang / ClassLoader;)Lorg / hibernate / boot / registry / BootstrapServiceRegistryBuilder; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) 在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) 在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4851) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) 在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1408) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1398) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745)
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
使用最新的hibernate(pom.xml)更改Hibernate版本:
<!-- Hibernate -->
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.10.Final</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.2.10.Final</version>
</dependency>
答案 1 :(得分:0)
Hie
问题出在ApplicationContextConfig.java类中。该类包含以下导入
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
如果要保留项目结构,则将这些导入更改为
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
注意我将hibernate5更改为hibernate4以匹配pom.xml中的依赖版本
这应该是另一种解决方案。
如果有帮助我想听听。
谢谢你的问候