问答详情
源自:2-7 单元测试

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

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


提问者:brucemeng 2018-04-22 15:24

个回答

  • 慕少1685431
    2018-04-23 16:06:04
    已采纳

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

  • champion_j
    2018-08-19 17:13:27

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

  • 慕田峪1952080
    2018-06-23 18:28:26

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

  • brucemeng
    2018-04-22 16:22:19

    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


  • brucemeng
    2018-04-22 16:21:34

    加了 1.6.1版本的,还是报错

  • SunshineKQ
    2018-04-22 15:42:52

    原因:缺少dom4j的jar包

    解决方法:引入dom4j.jar

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

    <dependency>

        <groupId>dom4j</groupId>

        <artifactId>dom4j</artifactId>

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

    </dependency>