为了账号安全,请及时绑定邮箱和手机立即绑定

启动单元测试报错,怎么回事?

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource


Caused by: java.lang.NoClassDefFoundError: org/dom4j/io/STAXEventReader

at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)

at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:179)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:149)

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory


正在回答

6 回答

可以去本地仓库看一下下载到了相应的包没有,看看下载到的包有没有问题,要是有问题就删了重新下,还是不行就到maven dependencies里面看看有没有加到项目里来,没有就加一下

0 回复 有任何疑惑可以回复我~
#1

brucemeng 提问者

非常感谢!
2018-04-24 回复 有任何疑惑可以回复我~

在maven里面处理一致不可以,可以通过build path -> libraries里面添加这个jar包,就可以了

0 回复 有任何疑惑可以回复我~

我也遇到同样的问题,包都有,就是报错,不懂什么原因

0 回复 有任何疑惑可以回复我~

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/dom4j/io/STAXEventReader

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)

at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:111)

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)

... 24 more

Caused by: java.lang.NoClassDefFoundError: org/dom4j/io/STAXEventReader

at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)

at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:179)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:149)

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54)

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)

... 39 more

Caused by: java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 49 more


0 回复 有任何疑惑可以回复我~
#1

yuwei2015

加完之后,选中项目右键--》Maven --》 update project, 然后到你的maven dependencies 看看 dom4j的jar是否加进来了。
2018-04-22 回复 有任何疑惑可以回复我~

加了 1.6.1版本的,还是报错

0 回复 有任何疑惑可以回复我~

原因:缺少dom4j的jar包

解决方法:引入dom4j.jar

<!-- https://mvnrepository.com/artifact/dom4j/dom4j -->

<dependency>

    <groupId>dom4j</groupId>

    <artifactId>dom4j</artifactId>

    <version>x.x.x</version>

</dependency>


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Spring Boot进阶之Web进阶
  • 参与学习       104040    人
  • 解答问题       393    个

《2小时学习Spring Boot》之进阶教程,针对Web方面的相关技巧

进入课程

启动单元测试报错,怎么回事?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信