引起:java.lang.ClassNotFoundException:org.dom4j.io.STAXEventReader [英] Caused by: java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader
问题描述
我正在开发一个Web服务应用程序,但sessionFactory bean由于下面的错误而没有创建。我看不到dom4j jar的重复或冲突版本。我尝试过不同的次数来重新清理服务器和eclipse中的项目。
Hibernate version 5.1.0.Final
原因:org.springframework.beans.factory.BeanCreationException:在ServletContext资源中定义名称为'sessionFactory'的Bean时创建错误[/WEB-INF/spring-database.xml]:调用init方法失败;嵌套异常是org.springframework上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
中的java.lang.NoClassDefFoundError:org / dom4j / io / STAXEventReader
。在org.springframework处
。org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
在org.springframework。
at 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)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFact ory.java:197)在org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192
)在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency
( DefaultListableBeanFactory.java:1116)
在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement。注意(AutowiredAnnotationBeanPostProcessor.java:545)
... 51 more
由java.lang.NoClassDefFoundError引起:org / dom4j / io / STAXEventReader
at org.hibernate.boot.spi.XmlMappingBinderAccess<初始化>(XmlMappingBinderAccess.java:43)在org.hibernate.boot.MetadataSources
将。INIT>(MetadataSources.java:87)
。在org.hibernate.cfg.Configuration。< init>(Configuration.java:124)
在org.springframework.orm.hibernate5.LocalSessionFactoryBuilder<初始化>(LocalSessionFactoryBuilder.java:110)
。在org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:309)
。在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
。 .. 61 more
导致:java.lang.ClassNotFoundException:org.dom4j.io.STAXEventReader from [模块deployment.web-services.war:mainfrom Service Module Loader ]在在org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
。在有机
。 jboss.modules.ConcurrentClassLoader.performLoadC lassChecked(ConcurrentClassLoader.java:404)
在org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
在org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
... 68 more
Spring-security.xml
<?xml version =1.0encoding =UTF-8?>
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexmlns :context =http://www.springframework.org/schema/context
xmlns:tx =http://www.springframework.org/schema/tx
xsi:schemaLocation = http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/上下文http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema /tx/spring-tx-3.0.xsd\">
< bean id =sessionFactory
class =org.springframework.orm.hibernate5.LocalSessionFactoryBean>
< property name =dataSourceref =dataSource/>
< property name =packagesToScan>
< list>
<值> com.foo.bar.entity< /值>
< / list>
< / property>
< property name =hibernateProperties>
<道具>
< prop key =hibernate.dialect> org.hibernate.dialect.MySQL5Dialect< / prop>
< prop key =current_session_context_class> thread< / prop>
< prop key =hibernate.show_sql> true< / prop>
< prop key =hibernate.validator.apply_to_ddl> true< / prop>
< prop key =hibernate.validator.autoregister_listeners> false< / prop>
< prop key =hibernate.hbm2ddl.auto>建立< / prop>
< /道具>
< / property>
< / bean>
<! - Transcation Manager - >
< tx:注解驱动的事务管理器=transactionManager/>
< bean id =transactionManager
class =org.springframework.orm.hibernate5.HibernateTransactionManager>
< property name =sessionFactoryref =sessionFactory/>
< / bean>
< bean id =dataSourceclass =org.springframework.jndi.JndiObjectFactoryBean>
< property name =jndiNamevalue =java:jboss / datasources / myDS/>
< / bean>
maven dependency:tree command give以下结果: -
--- maven-dependency-plugin:2.8:tree(default-cli)@ web-services - -
[INFO] com.car.buk:web-services:war:1.0
[INFO] + - com.car.buk:用户管理:jar:1.0:编译
[INFO] + - com.car.buk:entity:jar:1.0:编译
[INFO] + - org.slf4j:slf4j-api:jar:1.7.18:编译
[信息] + - com.fasterxml.jackson.core:jackson-databind:jar:2.5.3:compile
[INFO] | + - com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:编译
[INFO] + - org.hibernate:hibernate-core:jar:5.1.0.Final:compile
[INFO] | + - org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | + - org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | + - org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] | + - antlr:antlr:jar:2.7.7:编译
[INFO] | + - org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] | + - org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] | + - com.fasterxml:classmate:jar:1.3.0:compile
[INFO] | + - dom4j:dom4j:jar:1.6.1:编译
[INFO] | | \ -xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:编译
[INFO] + - org.hibernate:hibernate-entitymanager:jar:5.1.0.Final:compile
[INFO] + - org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] + - org.springframework:spring-beans:jar:4.2.5.RELEASE :编译
[INFO] + - org.springframework:spring-jdbc:jar:4.2.5.RELEASE:compile
[INFO] + - org.springframework:spring-orm:jar:4.2.5 .RELEASE:编译
[INFO] + - org.springframework:spring-tx:jar:4.2.5.RELEASE:compile
[INFO] + - org.springframework:spring-test:jar:4.2 .RELEASE:编译
[INFO] + - org.springframework:spring-context:jar:4.2.5.RELEASE:compile
[INFO] | + - org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.2.5.RELEASE:compile
[INFO] + - org.springframework:spring-web:jar:4.2.5.RELEASE:compile
[INFO] + - org.springframework:spring-webmvc:jar:4.2.5.RELEASE:compile
[INFO] + - org.springframework.security:spring-security-web:jar:4.0.4.RELEASE :编译
[INFO] | \- aopalliance:aopalliance:jar:1.0:编译
[INFO] + - org.springframework.security:spring-security-config:jar:4.0.4.RELEASE:compile
[INFO] + - org.springframework.security:spring-security-acl:jar:4.0.4.RELEASE:compile
[INFO] + - org.springframework.security:spring-security-core:jar:4.0.4.RELEASE :编译
[INFO] + - org.springframework.security.oauth:spring-security-oauth2:jar:2.0.9.RELEASE:compile
[INFO] | + - commons-codec:commons-codec:jar:1.9:编译
[INFO] | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] \ -junit:junit:jar:3.8.1:test
我完全被卡住了。您是否有任何人有任何线索如何解决这个问题? 解决方案
感谢指出版本问题。
Hibernate core 5.1.0 .Final包含dom4j-1.6.1这个引发
错误的jar包。要解决这个问题,需要从hibernate-core
中排除dom4j-1.6.1,并在你的pom中包含dom4j-1.6。
我无法找到发生这种情况的确切原因。
这就是我在hibernate依赖项中从pom中排除dom4j的原因。
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 5.1.0.Final< / version>
<排除项>
<排除>
< artifactId> jta< / artifactId>
< groupId> javax.transaction< / groupId>
< /排除>
<! - 排除SLF4j以避免版本冲突(我们有1.6.6,这在1.6.1中拖动
) - >
<排除>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< /排除>
<! - 排除dom4j以避免版本冲突(我们有1.6,这在1.6.1中拖动
) - >
<排除>
< groupId> dom4j< / groupId>
< artifactId> dom4j< / artifactId>
< /排除>
< /排除>
< /依赖关系>
I am developing a web service application but sessionFactory bean is not creating because of below error. I can't see duplicate or conflict version of dom4j jar. I tried various times to referesh/clean server and project in eclipse.
Hibernate version 5.1.0.Final
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-database.xml]: 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:1578)
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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 51 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.cfg.Configuration.<init>(Configuration.java:124)
at org.springframework.orm.hibernate5.LocalSessionFactoryBuilder.<init>(LocalSessionFactoryBuilder.java:110)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:309)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 61 more
Caused by: java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader from [Module "deployment.web-services.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
... 68 more
Spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>com.foo.bar.entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.validator.apply_to_ddl">true</prop>
<prop key="hibernate.validator.autoregister_listeners">false</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<!-- Transcation Manager -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/myDS" />
</bean>
maven dependency:tree command give below result:-
--- maven-dependency-plugin:2.8:tree (default-cli) @ web-services ---
[INFO] com.car.buk:web-services:war:1.0
[INFO] +- com.car.buk:user-management:jar:1.0:compile
[INFO] +- com.car.buk:entity:jar:1.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.18:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.5.3:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.1.0.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] | +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] | +- com.fasterxml:classmate:jar:1.3.0:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.1.0.Final:compile
[INFO] +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.2.5.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:4.0.4.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework.security:spring-security-config:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-acl:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-core:jar:4.0.4.RELEASE:compile
[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.9.RELEASE:compile
[INFO] | +- commons-codec:commons-codec:jar:1.9:compile
[INFO] | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] \- junit:junit:jar:3.8.1:test
I am totally stuck. Do any of you guys have any clue how to resolve this??
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>
这篇关于引起:java.lang.ClassNotFoundException:org.dom4j.io.STAXEventReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!