spring java.lang.NoClassDefFoundError: org/springframework/core/DefaultParameterNameDiscoverer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24686885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 06:49:25  来源:igfitidea点击:

java.lang.NoClassDefFoundError: org/springframework/core/DefaultParameterNameDiscoverer

springhibernate

提问by Kumar M

I am trying to work out my spring hibernate with maven dependencies.

我正在尝试使用 maven 依赖项来解决我的 spring 休眠问题。

My server is not starting up and throwing this error:

我的服务器没有启动并抛出这个错误:

java.lang.NoClassDefFoundError: org/springframework/core/DefaultParameterNameDiscoverer

I don't know whether it is a problem with my dependencies or with my server. Let me know if anything would be needed from my project. Here are the dependencies I've added in my pom.xml file. I am using maven 4.0.0.

我不知道是我的依赖项还是我的服务器有问题。让我知道我的项目是否需要任何东西。这是我在 pom.xml 文件中添加的依赖项。我正在使用 Maven 4.0.0。

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- Spring 3 dependencies -->
    <dependency> 
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId> 
        <version>${spring.version}</version> 
    </dependency> 

    <!-- <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>  -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.0.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.5.Final</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <!-- Hibernate annotation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.3.5.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.31</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>abc</id>
        <url>http://repo1.maven.org/maven2</url>
    </repository>
</repositories>

回答by Manuel Jordan

Is not wise mix Spring versions in one project.

在一个项目中混合 Spring 版本是不明智的。

The error is, you have the spring-coremodule working with 3.0.5and the rest of modules with 4.0.6

错误是,你有spring-core模块工作,3.0.5其余模块有4.0.6

回答by sylikon

Already posted ansewers are correct. This issue is caused by conflicts in dependency version. The fastest way in my opinion to resolve those confilcts is to use plugin:

已经发布的答案是正确的。此问题是由依赖版本冲突引起的。我认为解决这些冲突的最快方法是使用插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.4.1</version>
    <configuration>
        <rules><dependencyConvergence/></rules>
    </configuration>
</plugin>

Run it with mvn enforcer:enforce command. You will get a list of conficted dependencies. Check the library that has the lowest version of certain dependency and downgrade others. It is slow precess though so be patient

使用 mvn Enforcer:enforce 命令运行它。您将获得冲突的依赖项列表。检查具有某些依赖项的最低版本的库并降级其他库。虽然过程缓慢,但请耐心等待

回答by Smart Coder

Resolution to this problem would depend on your pom.xml and what spring library it has. Some rejig of the spring jars including and excluding spring jars in maven will resolve this.

此问题的解决方案取决于您的 pom.xml 及其拥有的 spring 库。包括和排除 maven 中的 spring jars 的 spring jars 的一些 rejig 将解决这个问题。

I added the following to resolve the mongo-db spring-data jar related issue.

<properties>
        <spring.version>3.2.4.RELEASE</spring.version>
        <spring.data.version>1.6.1.RELEASE</spring.data.version>
        <spring.core.version>4.1.4.RELEASE</spring.core.version>
    </properties>

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
            </exclusions>   
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.core.version}</version>                           
        </dependency>

            <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>${mongo.driver.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jongo</groupId>
            <artifactId>jongo</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>${spring.data.version}</version>
        </dependency>

回答by Chris Neve

As Manuel Jordan suggested, it is because of the difference in versions. I just got this error and solved it by setting the same version of org.springframework:spring-core in each one of my modules.

正如曼努埃尔·乔丹所说,这是因为版本不同。我刚刚收到这个错误并通过在我的每个模块中设置相同版本的 org.springframework:spring-core 来解决它。

My project structure is as follows:

我的项目结构如下:

projectname
    module1
    module2
    module3

I wrote a test under module2:

我在module2下写了一个测试:

projectname
    module1
    module2
        src
        test
            < my package >/TestClass.java
    module3

When I ran this test, I got this error:

当我运行这个测试时,我收到了这个错误:

 java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded

After ensuring each module had the same version of the org.springframework:spring-coredependency, the test ran.

在确保每个模块具有相同版本的org.springframework:spring-core依赖项后,测试运行。