Java 尝试初始化 Spring 时出现 AbstractMethodError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21140646/
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-08-13 06:52:08  来源:igfitidea点击:

AbstractMethodError when try to initialize Spring

javaspringmavenlog4jslf4j

提问by Skizzo

I'm developing an application with Spring, vaadin and maven like tool di project managment. Now when try to execute jetty:run i get the following error:

我正在使用 Spring、vaadin 和 maven 开发应用程序,例如工具 di 项目管理。现在,当尝试执行 jetty:run 我收到以下错误:

java.lang.AbstractMethodError: org.slf4j.impl.Log4jLoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)

This is my pom.xml

这是我的 pom.xml

  <!-- Logging dependencies   -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>com.springsource.org.apache.commons.logging</artifactId>
        <version>1.1.1</version>
    </dependency>


    <!-- Log4J dependencies -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>com.springsource.slf4j.log4j</artifactId>
        <version>1.5.6</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>com.springsource.slf4j.api</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.log4j</groupId>
        <artifactId>com.springsource.org.apache.log4j</artifactId>
        <version>1.2.15</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-ext</artifactId>
        <version>1.7.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.1</version>
        <scope>runtime</scope>
    </dependency>

     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
         <exclusions>
        <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
        <version>${spring.version}</version>
    </dependency>

How can do to solve this problem?

怎么办才能解决这个问题?

回答by dhamibirendra

There is conflict with the logging dependency that you have managed. Replace your dependency with below: This will resolve your dependency issue

与您管理的日志依赖项存在冲突。用以下替换您的依赖项:这将解决您的依赖项问题

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.6.1</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.26</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>0.9.26</version>
        </dependency>

回答by Skizzo

I solved commenting this two dependencies:

我解决了评论这两个依赖项的问题:

     <!-- Log4J dependencies 
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>com.springsource.slf4j.log4j</artifactId>
        <version>${slf4j.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>com.springsource.slf4j.api</artifactId>
        <version>${slf4j.log4j.api.version}</version>
    </dependency>
    -->

回答by nanospeck

For me the solution was to upgrade logback from 4.7 to 5.0

对我来说,解决方案是将 logback 从 4.7 升级到 5.0

<dependency>
        <groupId>net.logstash.logback</groupId>
        <artifactId>logstash-logback-encoder</artifactId>
        <version>5.0</version>
</dependency>