java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log

后端 未结 4 760
抹茶落季
抹茶落季 2020-12-17 09:19

I am getting this error while deploying my application

    java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Ma
      rker;Ljava         


        
相关标签:
4条回答
  • 2020-12-17 10:06

    I had the same problem when writing test cases while doing code refactoring in a Java 7 project. I fixed it by replacing the old logging imports by slf4j loggers

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    

    in addition to it my pom dependencies looked like-

            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.4</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.14</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.25</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
                <version>2.5.6</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>2.5.6</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>2.5.6</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc-struts</artifactId>
                <version>2.5.6</version>
                <exclusions>
                    <exclusion>
                        <groupId>struts</groupId>
                        <artifactId>struts</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
                <version>3.2.6.ga</version>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts-core</artifactId>
                <version>1.3.9</version>
                <exclusions>
                    <exclusion>
                        <groupId>antlr</groupId>
                        <artifactId>antlr</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts-taglib</artifactId>
                <version>1.3.9</version>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts-tiles</artifactId>
                <version>1.3.9</version>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts-extras</artifactId>
                <version>1.3.9</version>
            </dependency>
            <dependency>
                <groupId>axis</groupId>
                <artifactId>axis</artifactId>
                <version>1.4</version>
            </dependency>
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity</artifactId>
                <version>1.6</version>
            </dependency>
            <dependency>
                <groupId>velocity-tools</groupId>
                <artifactId>velocity-tools</artifactId>
                <version>1.4</version>
            </dependency>
            <dependency>
                <groupId>displaytag</groupId>
                <artifactId>displaytag</artifactId>
                <version>1.2.0-gema-2</version>
                <exclusions>
                    <exclusion>
                        <groupId>struts</groupId>
                        <artifactId>struts</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-webmvc</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>taglibs</groupId>
                        <artifactId>standard</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>commons-collections</groupId>
                        <artifactId>commons-collections</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>commons-beanutils</groupId>
                        <artifactId>commons-beanutils</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.lowagie</groupId>
                        <artifactId>itext</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts-el</artifactId>
                <version>1.3.9</version>
            </dependency>
            <dependency>
                <groupId>struts</groupId>
                <artifactId>struts-layout-wrapper</artifactId>
                <version>1.2.19</version>
                <exclusions>
                    <exclusion>
                        <groupId>struts</groupId>
                        <artifactId>struts</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>taglibs</groupId>
                <artifactId>standard</artifactId>
                <version>1.1.2</version>
            </dependency>
            <dependency>
                <groupId>com.lowagie</groupId>
                <artifactId>itext</artifactId>
                <version>1.4.8</version>
            </dependency>
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.1.1</version>
            </dependency>
            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
                <version>1.7.0</version>
            </dependency>
            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.4</version>
            </dependency>
            <dependency>
                <groupId>commons-digester</groupId>
                <artifactId>commons-digester</artifactId>
                <version>1.8</version>
            </dependency>
            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>3.2.1</version>
            </dependency>
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.2.0.3.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>de.gema.sso</groupId>
                <artifactId>gema-sso-client</artifactId>
                <version>1.2</version>
                <exclusions>
                    <exclusion>
                        <groupId>struts</groupId>
                        <artifactId>struts</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-web</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!--test -->
            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>1.2.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>2.5.6</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.dbunit</groupId>
                <artifactId>dbunit</artifactId>
                <version>2.4.4</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <filters>
            <filter>${basedir}/target/filter.properties</filter>
        </filters>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <!-- Safety -->
                                <mkdir dir="${project.build.directory}" />
                                <tstamp>
                                    <format property="build.time" pattern="yyyy-MM-dd hh:mm:ss" />
                                </tstamp>
                                <tstamp>
                                    <format property="build.nr" pattern="yyyyMMddhhmmss" />
                                </tstamp>
                                <echo file="${basedir}/target/filter.properties">
                                    buildNr=${build.nr}
                                    buildTime=${build.time}
                                </echo>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <extensions>
            <extension>
                <groupId>fr.jcgay.maven.extension</groupId>
                <artifactId>unique-revision-maven-filtering</artifactId>
                <version>1.0</version>
            </extension>
        </extensions>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
    
    0 讨论(0)
  • 2020-12-17 10:07

    I had the same problem in a Gradle project.

    The answers given here were useful. I just had to solve it in a Gradle way.

    Here is my solution:

    configurations.all {
        all*.exclude group: 'org.slf4j', module: 'jcl104-over-slf4j'
    }
    
    0 讨论(0)
  • 2020-12-17 10:11

    Use mvn dependency:tree to see which version of slf4j maven decides to give you. If it has picked the wrong version, you could use a dependency management section to specify which version you want.

    If the output of dependency:tree shows the correct version (i.e. a version which does contain the method it can't find), then add -verbose:class as a jvm argument to see where it is loading that class from (e.g. if deploying in jboss it might be loading it from its internal logging jars instead of your slf4j jars).

    0 讨论(0)
  • 2020-12-17 10:17

    dependency:treeis a usefull tool that's true.

    In addition, another way to fix it:

    while using Eclipse IDE, use SHIFT + CTRL + T to open following type "SLF4JLocationAwareLog"

    You should be able to find related library and so a potential conflict.

    Switch to the dependency tree view of the pom.xml to know the exclusion to add.

    In my case, was related to struts dependency jcl104-over-slf4j. I just exclude this one from the dependency:

            <dependency>
            <groupId>displaytag</groupId>
            <artifactId>displaytag</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl104-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
    0 讨论(0)
提交回复
热议问题