引起原因:java.lang.NoClassDefFoundError:org/springframework/core/log/LogMessage

发布于 2025-01-11 08:46:56 字数 8798 浏览 0 评论 0原文

我正在使用 Spring 和 JPA(不是 Spring-Boot),当我尝试启动单元测试时出现此错误:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContextTest.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/log/LogMessage

我正在尝试将持久层迁移到 JPA,但当我从 IntelliJ 启动单元测试时遇到此

问题是我的单元测试注释:

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = { "classpath:applicationContextTest.xml" })

这是我的applicationContextTest.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
                    http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-4.1.xsd
                    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
                    http://www.springframework.org/schema/data/jpa
                    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"

default-autowire="byName">


<!-- Scans the classpath for annotated components that will be auto-registered
    as Spring beans. For example @Component, @Controller and @Service. Make sure
    to set the correct base-package -->
<context:component-scan
    base-package="com.mypackage.persistence, " />

<jpa:repositories base-package="com.mypackage.persistence.dao.jpa" />

<!-- Read any *.properties file -->
<context:property-placeholder location="classpath*:*.properties" />


<!-- Default Entity Manager defined in @Qualifier(value = "myProjectManagerFactory")
    of GenericDao -->
<bean id="myProjectManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="defaultPersistenceUnit" />
    <property name="packagesToScan">
        <list>
            <value>com.mypackage.persistence.**.*</value>
        </list>
    </property>
    <property name="jpaVendorAdapter" ref="hibernateVendor" />
    <property name="jpaProperties" ref="myProjectJpaProperties" />
</bean>

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

这是我的pom.xml spring依赖项

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Various Application Context utilities, including EhCache, JavaMail, 
        Quartz, and Freemarker integration Define this if you need any of these integrations -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Spring AOP + AspectJ -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Support for testing Spring applications with tools such as JUnit and 
        TestNG This artifact is generally always defined with a 'test' scope for 
        the integration testing framework and unit testing stubs -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>

我正在使用4.3.16.RELEASE Spring版本

我尝试过但没有成功这个问题

带有 primefaces 的 Spring 启动给出错误:java.lang.NoClassDefFoundError :org/springframework/core/log/LogMessage

我使用 mvn 依赖项获得了这个

--------------------< com.xx:myProject-persistence >----------------------
Building Uitgedbreid SportMedisch Onderzoek (Persistence) 2.8.8-SNAPSHOT
--------------------------------[ jar ]---------------------------------
Downloading from snapshots: https://artifactory.xx.com:443/artifactory/libs-snapshot/com/xx/myProject/2.8.8-SNAPSHOT/maven-metadata.xml
 
--- maven-dependency-plugin:2.8:tree(default-cli) @ myProject-persistence ---
 com.xx:myProject-persistence:jar:2.8.8-SNAPSHOT
 +- com.xx:database-encryptor:jar:0.2.5:compile
 +- com.xx:infographic-engine:jar:1.0.1:compile
 |  \- com.xx:common-utils:jar:1.1.5:compile (version selected from constraint [1.1,1.2))
 |     +- ch.qos.logback:logback-core:jar:1.2.6:compile
 |     +- ch.qos.logback:logback-classic:jar:1.2.6:compile
 |     \- javax.mail:mail:jar:1.4.7:compile
 |        \- javax.activation:activation:jar:1.1:compile
 +- com.xx:jpa-schema-exporter:jar:0.5.1:compile
 +- com.xx:myProject-logger:jar:2.8.8-SNAPSHOT:compile
 |  +- org.springframework:spring-context:jar:4.3.16.RELEASE:compile
 |  |  \- org.springframework:spring-expression:jar:4.3.16.RELEASE:compile
 |  \- org.springframework:spring-aspects:jar:4.3.16.RELEASE:compile
 +- mysql:mysql-connector-java:jar:5.1.27:compile
 +- org.hibernate:hibernate-core:jar:5.2.17.Final:compile
 |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
 |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
 |  +- org.javassist:javassist:jar:3.22.0-GA:compile
 |  +- antlr:antlr:jar:2.7.7:compile
 |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.1.Final:compile
 |  +- org.jboss:jandex:jar:2.0.3.Final:compile
 |  +- com.fasterxml:classmate:jar:1.3.0:compile
 |  +- dom4j:dom4j:jar:1.6.1:compile
 |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
 +- com.mchange:c3p0:jar:0.9.5.2:compile
 |  \- com.mchange:mchange-commons-java:jar:0.2.11:compile
 +- net.sf.ehcache:ehcache:jar:2.10.3:compile
 |  \- org.slf4j:slf4j-api:jar:1.7.7:compile
 +- org.hibernate:hibernate-ehcache:jar:5.2.17.Final:compile
 +- org.hibernate:hibernate-entitymanager:jar:5.2.17.Final:compile
 |  \- net.bytebuddy:byte-buddy:jar:1.6.14:compile
 +- org.springframework:spring-orm:jar:4.3.16.RELEASE:compile
 |  +- org.springframework:spring-beans:jar:4.3.16.RELEASE:compile
 |  +- org.springframework:spring-core:jar:4.3.16.RELEASE:compile
 |  |  \- commons-logging:commons-logging:jar:1.2:compile
 |  +- org.springframework:spring-jdbc:jar:4.3.16.RELEASE:compile
 |  \- org.springframework:spring-tx:jar:4.3.16.RELEASE:compile
 +- org.springframework:spring-context-support:jar:4.3.16.RELEASE:compile
 +- org.springframework:spring-aop:jar:4.3.16.RELEASE:compile
 +- org.springframework:spring-test:jar:4.3.16.RELEASE:test
 +- org.aspectj:aspectjrt:jar:1.8.2:compile
 +- org.aspectj:aspectjweaver:jar:1.8.2:compile
 +- com.h2database:h2:jar:1.4.182:test

 +- com.google.code.gson:gson:jar:2.3.1:compile
 +- commons-io:commons-io:jar:2.4:compile
 +- org.testng:testng:jar:6.14.3:test
 |  +- com.beust:jcommander:jar:1.72:test
 |  \- org.apache-extras.beanshell:bsh:jar:2.0b6:test
 +- junit:junit:jar:4.12:test
 |  \- org.hamcrest:hamcrest-core:jar:1.3:test
 +- xml-apis:xml-apis:jar:1.4.01:compile
 \- javax.interceptor:javax.interceptor-api:jar:3.1:compile

I'm using Spring and JPA (not Spring-Boot) and I have this error when I try to launch Unit Tests:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContextTest.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/log/LogMessage

I am trying to migrate the persistence layer to JPA but I have this problem when I launch a Unit Test from IntelliJ

This is my Unit Test Annotations:

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = { "classpath:applicationContextTest.xml" })

This is my applicationContextTest.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
                    http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-4.1.xsd
                    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
                    http://www.springframework.org/schema/data/jpa
                    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"

default-autowire="byName">


<!-- Scans the classpath for annotated components that will be auto-registered
    as Spring beans. For example @Component, @Controller and @Service. Make sure
    to set the correct base-package -->
<context:component-scan
    base-package="com.mypackage.persistence, " />

<jpa:repositories base-package="com.mypackage.persistence.dao.jpa" />

<!-- Read any *.properties file -->
<context:property-placeholder location="classpath*:*.properties" />


<!-- Default Entity Manager defined in @Qualifier(value = "myProjectManagerFactory")
    of GenericDao -->
<bean id="myProjectManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="defaultPersistenceUnit" />
    <property name="packagesToScan">
        <list>
            <value>com.mypackage.persistence.**.*</value>
        </list>
    </property>
    <property name="jpaVendorAdapter" ref="hibernateVendor" />
    <property name="jpaProperties" ref="myProjectJpaProperties" />
</bean>

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

And this is my pom.xml spring dependencies

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Various Application Context utilities, including EhCache, JavaMail, 
        Quartz, and Freemarker integration Define this if you need any of these integrations -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Spring AOP + AspectJ -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Support for testing Spring applications with tools such as JUnit and 
        TestNG This artifact is generally always defined with a 'test' scope for 
        the integration testing framework and unit testing stubs -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>

I am using 4.3.16.RELEASE Spring Version

I have tried without success this question

spring boot with primefaces give error : java.lang.NoClassDefFoundError: org/springframework/core/log/LogMessage

I obtained this using mvn dependency

--------------------< com.xx:myProject-persistence >----------------------
Building Uitgedbreid SportMedisch Onderzoek (Persistence) 2.8.8-SNAPSHOT
--------------------------------[ jar ]---------------------------------
Downloading from snapshots: https://artifactory.xx.com:443/artifactory/libs-snapshot/com/xx/myProject/2.8.8-SNAPSHOT/maven-metadata.xml
 
--- maven-dependency-plugin:2.8:tree(default-cli) @ myProject-persistence ---
 com.xx:myProject-persistence:jar:2.8.8-SNAPSHOT
 +- com.xx:database-encryptor:jar:0.2.5:compile
 +- com.xx:infographic-engine:jar:1.0.1:compile
 |  \- com.xx:common-utils:jar:1.1.5:compile (version selected from constraint [1.1,1.2))
 |     +- ch.qos.logback:logback-core:jar:1.2.6:compile
 |     +- ch.qos.logback:logback-classic:jar:1.2.6:compile
 |     \- javax.mail:mail:jar:1.4.7:compile
 |        \- javax.activation:activation:jar:1.1:compile
 +- com.xx:jpa-schema-exporter:jar:0.5.1:compile
 +- com.xx:myProject-logger:jar:2.8.8-SNAPSHOT:compile
 |  +- org.springframework:spring-context:jar:4.3.16.RELEASE:compile
 |  |  \- org.springframework:spring-expression:jar:4.3.16.RELEASE:compile
 |  \- org.springframework:spring-aspects:jar:4.3.16.RELEASE:compile
 +- mysql:mysql-connector-java:jar:5.1.27:compile
 +- org.hibernate:hibernate-core:jar:5.2.17.Final:compile
 |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
 |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
 |  +- org.javassist:javassist:jar:3.22.0-GA:compile
 |  +- antlr:antlr:jar:2.7.7:compile
 |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.1.Final:compile
 |  +- org.jboss:jandex:jar:2.0.3.Final:compile
 |  +- com.fasterxml:classmate:jar:1.3.0:compile
 |  +- dom4j:dom4j:jar:1.6.1:compile
 |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
 +- com.mchange:c3p0:jar:0.9.5.2:compile
 |  \- com.mchange:mchange-commons-java:jar:0.2.11:compile
 +- net.sf.ehcache:ehcache:jar:2.10.3:compile
 |  \- org.slf4j:slf4j-api:jar:1.7.7:compile
 +- org.hibernate:hibernate-ehcache:jar:5.2.17.Final:compile
 +- org.hibernate:hibernate-entitymanager:jar:5.2.17.Final:compile
 |  \- net.bytebuddy:byte-buddy:jar:1.6.14:compile
 +- org.springframework:spring-orm:jar:4.3.16.RELEASE:compile
 |  +- org.springframework:spring-beans:jar:4.3.16.RELEASE:compile
 |  +- org.springframework:spring-core:jar:4.3.16.RELEASE:compile
 |  |  \- commons-logging:commons-logging:jar:1.2:compile
 |  +- org.springframework:spring-jdbc:jar:4.3.16.RELEASE:compile
 |  \- org.springframework:spring-tx:jar:4.3.16.RELEASE:compile
 +- org.springframework:spring-context-support:jar:4.3.16.RELEASE:compile
 +- org.springframework:spring-aop:jar:4.3.16.RELEASE:compile
 +- org.springframework:spring-test:jar:4.3.16.RELEASE:test
 +- org.aspectj:aspectjrt:jar:1.8.2:compile
 +- org.aspectj:aspectjweaver:jar:1.8.2:compile
 +- com.h2database:h2:jar:1.4.182:test

 +- com.google.code.gson:gson:jar:2.3.1:compile
 +- commons-io:commons-io:jar:2.4:compile
 +- org.testng:testng:jar:6.14.3:test
 |  +- com.beust:jcommander:jar:1.72:test
 |  \- org.apache-extras.beanshell:bsh:jar:2.0b6:test
 +- junit:junit:jar:4.12:test
 |  \- org.hamcrest:hamcrest-core:jar:1.3:test
 +- xml-apis:xml-apis:jar:1.4.01:compile
 \- javax.interceptor:javax.interceptor-api:jar:3.1:compile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文