NANDHA KUMAR
NANDHA KUMAR

Reputation: 503

mvn spring-boot: run throwing log4j errors

I am new to Java. I am facing errors while execute the command mvn spring-boot: run. Can anyone help me to solve the issue. Screenshot attached here.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/langscape/.m2/repository/org/slf4j/slf4j-simple/1.7.28/slf4j-simple-1.7.28.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/langscape/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/langscape/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/home/langscape/.m2/repository/org/slf4j/slf4j-simple/1.7.28/slf4j-simple-1.7.28.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory
        at org.springframework.util.Assert.instanceCheckFailed(Assert.java:696)
        at org.springframework.util.Assert.isInstanceOf(Assert.java:596)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:281)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:104)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:238)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:219)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
        at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:70)
        at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
        at com.ailaysa.translate.v1.TranslateApplication.main(TranslateApplication.java:15)

pom.xml file link below you can see pom xml file here

Here is the list of dependencies in the pom.xml file:

<pom>
...
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
...
    <dependencies>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-thymeleaf</artifactId>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-web</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>org.codehaus.woodstox</groupId>
                    <artifactId>stax2-api</artifactId><!-- 4.1 conflicts with 3.1.4 from apache cxf-spring-boot-starter-jaxws-->
                </exclusion>

            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
            <version>1.3.8.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>1.5.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.5.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.10</version>
        </dependency>

<!--        okapi-->

        <dependency>
            <groupId>net.sf.okapi</groupId>
            <artifactId>okapi-core</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-html</artifactId>
            <version>1.40.0</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>net.sf.okapi.steps</groupId>-->
<!--            <artifactId>okapi-step-wordcount</artifactId>-->
<!--            <version>1.40.0</version>-->
<!--        </dependency>-->
        <dependency>
            <groupId>net.sf.okapi.lib</groupId>
            <artifactId>okapi-lib-segmentation</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.tm</groupId>
            <artifactId>okapi-tm-pensieve</artifactId>
            <version>0.36</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sf.okapi.filters/okapi-filter-json -->
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-json</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-table</artifactId>
            <version>1.40.0</version>
        </dependency>

        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-openoffice</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-openxml</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-properties</artifactId>
            <version>1.40.0</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>net.sf.okapi.filters</groupId>-->
<!--            <artifactId>okapi-filter-fontmappings</artifactId>-->
<!--            <version>1.40.0</version>-->
<!--        </dependency>-->
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-po</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-its</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-idml</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-markdown</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-rtf</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-sdlpackage</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-xliff2</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.filters</groupId>
            <artifactId>okapi-filter-ts</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-wordcount</artifactId>
            <version>1.40.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-tradosutils</artifactId>
            <version>0.37</version>
        </dependency>
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-common</artifactId>
            <version>1.40.0</version>
<!--            <scope>test</scope>-->
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sf.okapi.steps/okapi-step-common -->



        <!-- https://mvnrepository.com/artifact/net.sf.okapi.steps/okapi-step-leveraging -->
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-leveraging</artifactId>
            <version>1.40.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sf.okapi.steps/okapi-step-repetitionanalysis -->
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-repetitionanalysis</artifactId>
            <version>1.40.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/net.sf.okapi.steps/okapi-step-scopingreport -->
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-scopingreport</artifactId>
            <version>1.40.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sf.okapi.steps/okapi-step-segmentation -->
        <dependency>
            <groupId>net.sf.okapi.steps</groupId>
            <artifactId>okapi-step-segmentation</artifactId>
            <version>1.40.0</version>
<!--            <scope>test</scope>-->
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sf.okapi.connectors/okapi-connector-pensieve -->
        <dependency>
            <groupId>net.sf.okapi.connectors</groupId>
            <artifactId>okapi-connector-pensieve</artifactId>
            <version>1.40.0</version>
        </dependency>


        <!--        <dependency>-->
<!--            <groupId>ldapjdk</groupId>-->
<!--            <artifactId>ldapjdk</artifactId>-->
<!--            <scope>system</scope>-->
<!--            <version>1.0</version>-->
<!--            <systemPath>/home/langscape/Documents/okapi/installation/lib/okapi-lib-1.41.0.jar</systemPath>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>ldapjdk</groupId>-->
<!--            <artifactId>ldapjdk</artifactId>-->
<!--            <scope>system</scope>-->
<!--            <version>1.0</version>-->
<!--            <systemPath>/home/langscape/Documents/okapi/installation/lib/okapi-lib-ui-1.41.0.jar</systemPath>-->
<!--        </dependency>-->

<!--        <dubug >-->


        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.12.1</version>
<!--            <scope>test</scope>-->
        </dependency>

        <dependency>
            <groupId>com.twelvemonkeys.common</groupId>
            <artifactId>common-io</artifactId>
            <version>3.3.2</version>
        </dependency>
        <!-- Thanks for using https://jar-download.com -->

        <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<!--        <dependency>-->
<!--            <groupId>org.apache.lucene</groupId>-->
<!--            <artifactId>lucene-core</artifactId>-->
<!--            <version>8.7.0</version>-->
<!--        </dependency>-->

        <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<!--        <dependency>-->
<!--            <groupId>org.apache.lucene</groupId>-->
<!--            <artifactId>lucene-core</artifactId>-->
<!--            <version>7.6.0</version>-->
<!--        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.ibm.icu/icu4j-localespi -->
        <dependency>
            <groupId>com.ibm.icu</groupId>
            <artifactId>icu4j-localespi</artifactId>
            <version>68.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.htmlparser.jericho/jericho-html -->
        <dependency>
            <groupId>net.htmlparser.jericho</groupId>
            <artifactId>jericho-html</artifactId>
            <version>3.4</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.ibm.icu/icu4j -->

        <!--        <debug></debug>-->
        <!-- https://mvnrepository.com/artifact/com.ibm.icu/com.springsource.com.ibm.icu -->


    </dependencies>
...
</pom>

Upvotes: 1

Views: 446

Answers (1)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16115

There are two main problems in your dependencies:

  • you mix spring-boot-starter-* dependencies from several different versions,
  • you override the versions of some managed dependencies. Spring Boot manages the versions of hundreds of artifacts (cf. complete list): you should not specify a <version> tag for those artifacts.

After these changes your Spring Boot dependencies (I assume you want Log4j 2.x, not Log4j 1.2) become:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

Besides that use mvn dependency:tree or a similar functionality in your IDE to find out the dependency that pulls log4j (version 1.2) and logback-classic and exclude those transitive dependencies. You have one such dependency:

    <dependency>
      <groupId>net.sf.okapi.steps</groupId>
      <artifactId>okapi-step-tradosutils</artifactId>
      <version>0.37</version>
      <exclusions>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

Upvotes: 2

Related Questions