依赖缺失了吗? java.lang.NoSuchMethodError [英] Dependency missing? java.lang.NoSuchMethodError

查看:229
本文介绍了依赖缺失了吗? java.lang.NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编程方面有一定的经验,但是对Maven来说还很陌生.在我的最新项目中,我正在使用Apache Commons API(配置,cli等).它可以编译,但是在运行时抛出NoSuchMethod-exception.

I'm somewhat experienced in programming but pretty new to Maven. In my latest project I'm using the Apache Commons API (configuration, cli and so on). It compiles but throws me a NoSuchMethod-exception on runtime.

我的依赖项如下:

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.3</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-configuration2</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.4</version>
    </dependency>

这是发生错误的方法:

private Configuration parseConfig(String path) {
        File configFile = new File(path);
        if(!configFile.exists() || configFile.isDirectory()) {
            // Error config file path invalid
            CustomLogger.warn("ERROR file not found");
        }
        Configurations configs = new Configurations();
        Configuration config = null;
        try {
            config = configs.properties(configFile);
        }
        catch (ConfigurationException cex) {
            // Something went wrong
            CustomLogger.warn("Config Exception");
            cex.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return config;
    }

确切发生错误的行/零件/块是:

The line/part/block where the error is happening exactly is:

try {
    config = configs.properties(configFile);
}

堆栈跟踪为:

java.lang.NoSuchMethodError: org.apache.commons.beanutils.PropertyUtilsBean.addBeanIntrospector(Lorg/apache/commons/beanutils/BeanIntrospector;)V
        at org.apache.commons.configuration2.beanutils.BeanHelper.initBeanUtilsBean(BeanHelper.java:631)
        at org.apache.commons.configuration2.beanutils.BeanHelper.<clinit>(BeanHelper.java:89)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.sun.proxy.$Proxy0.<clinit>(Unknown Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
        at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:294)
        at org.apache.commons.configuration2.builder.fluent.Parameters.fileBased(Parameters.java:185)
        at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:602)
        at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:614)
        at org.apache.commons.configuration2.builder.fluent.Configurations.fileBasedBuilder(Configurations.java:132)
        at org.apache.commons.configuration2.builder.fluent.Configurations.propertiesBuilder(Configurations.java:238)
        at org.apache.commons.configuration2.builder.fluent.Configurations.properties(Configurations.java:282)
        at com.core.utils.CustomConfiguration.parseConfig(CustomConfiguration.java:130)

我想念什么?在Stack Overflow上有几篇文章建议在依赖项中包括"commons-beanutils".这样做并没有改变任何东西.任何帮助表示赞赏.

What am I missing? There are several posts out there on Stack Overflow suggesting to include "commons-beanutils" in the dependencies. Doing so didn't change anything. Any help appreciated.

推荐答案

它不是缺少的依赖项.在编译时和运行时,依赖关系之间是不一致的.

It is not a missing dependency. It is an inconsistency between the dependencies at compile time and at runtime.

问题在于org.apache.commons.beanutils.PropertyUtilsBean.addBeanIntrospector方法是在Apache Commons BeanUtils的1.8.3和1.9.0之间添加的.

The problem is that the org.apache.commons.beanutils.PropertyUtilsBean.addBeanIntrospector method was added between 1.8.3 and 1.9.0 of Apache Commons BeanUtils.

POM依赖关系表明您正在根据1.9.3编译代码,但是有证据表明您的JVM在运行时加载了较旧的版本.检查您的运行时类路径/WAR文件/等等,以确保您只有一个BeanUtils JAR,并且它是正确的版本.

The POM dependencies say that you are compiling your code against 1.9.3, but the evidence is that your JVM is loading an older version at runtime. Check your runtime classpath / WAR file / whatever to ensure that you have only one BeanUtils JAR, and that it is the correct version.

您的POM文件的依存关系之间可能会引起不明显的冲突.您可以通过使用Maven依赖插件来打印出依赖树来诊断此问题:

It is possible that there is an unnoticed conflict between your POM file's dependencies. You can diagnose this by using the Maven Dependency Plugin to print out the dependency tree:

这篇关于依赖缺失了吗? java.lang.NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆