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

大城市里の小女人 提交于 2019-11-27 15:53:47
Manish

Thanks to Hohenheim to point out the version issue.

Hibernate core 5.1.0.Final include dom4j-1.6.1 jar which throws this error. To fix this, need to exclude dom4j-1.6.1 from hibernate-core and include dom4j-1.6 in your pom.

I am not able find the exact reason why this is happening.

This is how I excluded dom4j from pom in hibernate dependency.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.1.0.Final</version>
    <exclusions>
        <exclusion>
            <artifactId>jta</artifactId>
            <groupId>javax.transaction</groupId>
        </exclusion>
        <!-- Exclude SLF4j to avoid version conflicts (we have 1.6.6, this drags 
                in 1.6.1) -->
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <!-- Exclude dom4j to avoid version conflicts (we have 1.6, this drags 
                in 1.6.1) -->
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

I used Ivy dependency manager and in my case I remove dom4j from core dependency and again add the last version 1.6.1 and that worked for me.

<dependency org="org.hibernate" name="hibernate-core" rev="5.2.8.Final">
    <exclude  org="dom4j"/>
</dependency>

<dependency org="dom4j" name="dom4j" rev="1.6.1"/>

In my case with the same problem I solve it setting this versions in pom.xml:

  • Spring version 4.3.7.RELEASE
  • Hibernate version 4.1.9.Final

I did't use <exclusions> at all and I added dom4j with version 1.4.

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.4</version>
</dependency> 

In my scenario, same stacktrace, I followed the answers without success. The solution was to remove dom4j from .m2/repository because apparently the jar was corrupt, and after downloaded again the problem was fixed.

Binoy Cherian

You won't need to apply exclusions. Simply fix this by deleting your local repository and then re download libraries by doing the Alt+F5 + force update.

Doing this solved the issue for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!