当前位置: 首页 > 知识库问答 >
问题:

Apache Storm:SLF4J:类路径包含多个SLF4J绑定

燕英逸
2023-03-14

我工作在一个样本拓扑(一个喷口ont螺栓),但当我使用命令行运行我的Storm项目:

storm jar目标/连接器-0.0.1-SNAPSHOT-jar-with-dependencies。jar拓扑。连接拓扑

我得到了错误

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/share/storm/lib/log4j-slf4j-impl-2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.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.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.apache.storm.config$read_storm_config.invoke(config.clj:78)
        at org.apache.storm.config$fn__904.invoke(config.clj:100)
        at org.apache.storm.config__init.load(Unknown Source)
        at org.apache.storm.config__init.<clinit>(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:278)
        at clojure.lang.RT.classForName(RT.java:2154)
        at clojure.lang.RT.classForName(RT.java:2163)
        at clojure.lang.RT.loadClassForName(RT.java:2182)
        at clojure.lang.RT.load(RT.java:436)
        at clojure.lang.RT.load(RT.java:412)
        at clojure.core$load$fn__5448.invoke(core.clj:5866)
        at clojure.core$load.doInvoke(core.clj:5865)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invoke(core.clj:5671)
        at clojure.core$load_lib$fn__5397.invoke(core.clj:5711)
        at clojure.core$load_lib.doInvoke(core.clj:5710)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invoke(core.clj:632)
        at clojure.core$load_libs.doInvoke(core.clj:5753)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invoke(core.clj:634)
        at clojure.core$use.doInvoke(core.clj:5843)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at org.apache.storm.command.config_value$loading__5340__auto____12655.invoke(config_value.clj:16)
        at org.apache.storm.command.config_value__init.load(Unknown Source)
        at org.apache.storm.command.config_value__init.<clinit>(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:278)
        at clojure.lang.RT.classForName(RT.java:2154)
        at clojure.lang.RT.classForName(RT.java:2163)
        at clojure.lang.RT.loadClassForName(RT.java:2182)
        at clojure.lang.RT.load(RT.java:436)
        at clojure.lang.RT.load(RT.java:412)
        at clojure.core$load$fn__5448.invoke(core.clj:5866)
        at clojure.core$load.doInvoke(core.clj:5865)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.lang.Var.invoke(Var.java:379)
        at org.apache.storm.command.config_value.<clinit>(Unknown Source)
Caused by: java.lang.RuntimeException: java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/defaults.yaml, jar:file:/usr/share/storm/lib/storm-core-1.0.0.jar!/defaults.yaml]
        at org.apache.storm.utils.Utils.findAndReadConfigFile(Utils.java:307)
        at org.apache.storm.utils.Utils.readDefaultConfig(Utils.java:351)
        at org.apache.storm.utils.Utils.readStormConfig(Utils.java:387)
        at org.apache.storm.utils.Utils.<clinit>(Utils.java:119)
        ... 39 more
Caused by: java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/defaults.yaml, jar:file:/usr/share/storm/lib/storm-core-1.0.0.jar!/defaults.yaml]
        at org.apache.storm.utils.Utils.getConfigFileInputStream(Utils.java:333)
        at org.apache.storm.utils.Utils.findAndReadConfigFile(Utils.java:287)
        ... 42 more
Running: java -client -Ddaemon.name= -Dstorm.options= -Dstorm.home=/usr/share/storm -Dstorm.log.dir=/usr/share/storm/logs -Djava.library.path= -Dstorm.conf.file= -cp /usr/share/storm/lib/disruptor-3.3.2.jar:/usr/share/storm/lib/storm-core-1.0.0.jar:/usr/share/storm/lib/slf4j-api-1.7.7.jar:/usr/share/storm/lib/objenesis-2.1.jar:/usr/share/storm/lib/log4j-core-2.1.jar:/usr/share/storm/lib/log4j-api-2.1.jar:/usr/share/storm/lib/reflectasm-1.10.1.jar:/usr/share/storm/lib/storm-rename-hack-1.0.0.jar:/usr/share/storm/lib/asm-5.0.3.jar:/usr/share/storm/lib/clojure-1.7.0.jar:/usr/share/storm/lib/log4j-over-slf4j-1.6.6.jar:/usr/share/storm/lib/servlet-api-2.5.jar:/usr/share/storm/lib/kryo-3.0.3.jar:/usr/share/storm/lib/minlog-1.3.0.jar:/usr/share/storm/lib/log4j-slf4j-impl-2.1.jar:target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/usr/share/storm/conf:/usr/share/storm/bin -Dstorm.jar=target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar topology.ConnectorTopology
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/share/storm/lib/log4j-slf4j-impl-2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.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.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.apache.storm.topology.BaseConfigurationDeclarer.<init>(BaseConfigurationDeclarer.java:26)
        at org.apache.storm.topology.TopologyBuilder$ConfigGetter.<init>(TopologyBuilder.java:406)
        at org.apache.storm.topology.TopologyBuilder$SpoutGetter.<init>(TopologyBuilder.java:423)
        at org.apache.storm.topology.TopologyBuilder.setSpout(TopologyBuilder.java:295)
        at org.apache.storm.topology.TopologyBuilder.setSpout(TopologyBuilder.java:278)
        at topology.ConnectorTopology.main(ConnectorTopology.java:34)
Caused by: java.lang.RuntimeException: java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/defaults.yaml, jar:file:/usr/share/storm/lib/storm-core-1.0.0.jar!/defaults.yaml]
        at org.apache.storm.utils.Utils.findAndReadConfigFile(Utils.java:307)
        at org.apache.storm.utils.Utils.readDefaultConfig(Utils.java:351)
        at org.apache.storm.utils.Utils.readStormConfig(Utils.java:387)
        at org.apache.storm.utils.Utils.<clinit>(Utils.java:119)
        ... 6 more
Caused by: java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/defaults.yaml, jar:file:/usr/share/storm/lib/storm-core-1.0.0.jar!/defaults.yaml]
        at org.apache.storm.utils.Utils.getConfigFileInputStream(Utils.java:333)
        at org.apache.storm.utils.Utils.findAndReadConfigFile(Utils.java:287)
        ... 9 more

我的pom文件配置:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.project.connector</groupId>
        <artifactId>connector</artifactId>
        <version>0.0.1-SNAPSHOT</version>


<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.project.connector.ConnectorTopology</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>

    </plugin>
  </plugins>
</build>

        <dependencies>

                <dependency>
                        <groupId>com.rabbitmq</groupId>
                        <artifactId>amqp-client</artifactId>
                        <version>3.6.1</version>
                </dependency>

                <dependency>
                        <groupId>org.eclipse.paho</groupId>
                        <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
                        <version>1.0.2</version>
                </dependency>

                <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-utils</artifactId>
                        <version>3.0.22</version>
                </dependency>

                <dependency>
                        <groupId>org.apache.storm</groupId>
                        <artifactId>storm-core</artifactId>
                        <version>1.0.0</version>
                </dependency>


        </dependencies>
</project>

我尝试了许多我在网上找到的解决方案,但没有结果。你知道问题的来源吗?

共有3个答案

孙成益
2023-03-14

我通过添加以下内容解决了问题:

<scope>provided</scope>

<exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>logback-classic</groupId>
                    <artifactId>ch.qos.logback</artifactId>
                </exclusion>
            </exclusions>

这样地:

<dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-core</artifactId>
            <version>1.0.0</version>

            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>logback-classic</groupId>
                    <artifactId>ch.qos.logback</artifactId>
                </exclusion>
            </exclusions>

        </dependency>
李光华
2023-03-14

SLF4J多重绑定会导致出现警告消息,但您的程序将继续运行。您看到的异常的原因在您的堆栈跟踪中:

原因:java。lang.RuntimeException:java。io。IOException:找到多个默认值。yaml资源。您可能正在将Storm jar与拓扑jar捆绑在一起。[jar:file:/root/cloud/connector/target/connector-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/defaults.yaml,jar:file:/usr/share/storm/lib/storm-core-1.0.0.jar!/defaults.yaml]

消除重复的默认值。yaml在您的jar中。

金瑞
2023-03-14

你会在这里找到一个解决方案:http://www.slf4j.org/codes.html#multiple_bindings

在可能导致冲突的依赖项(pom.xml)中添加排除。

<exclusions>
   <exclusion>  
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.7.xx</version>
   </exclusion>
</exclusions> 
 类似资料:
  • 我得到以下错误。似乎有多个日志记录框架绑定到SLF4J。不知道该怎么解决。非常感谢任何帮助。

  • 我的应用程序服务器ibm WebSphere。我在应用程序服务器日志中得到以下错误。哪里可以设置websphere? [19.09.2012 14:56:54:940 EEST]0000000a SystemErr R SLF4J:类路径包含多个SLF4J绑定。 [19.09.2012 14:56:54:940 EEST]0000000a SystemErr R SLF4J:在[wsjar:fil

  • 我在运行java代码时遇到以下运行时异常。有人能帮我解决绑定冲突吗。

  • 我在netbeans中有一个纯Java项目,我得到的警告是: 当然,我搜索了警告,但所有的答案都与用maven或pom.xml文件删除重复绑定有关。但是我没有pom.xml文件,也没有使用Maven。 那么如何排除绑定呢?

  • 我在其他问题中看到,通常此警告的解决方案是从导致此冲突的依赖项中排除slf4j,但我无法在我的项目中发现问题。 我运行命令,输出如下:

  • 在将apache.mahout添加到pom.xml之后,我在运行spring项目时开始出现这个警告,我想知道如何抑制这个警告。 这是我的pom.xml 我试图排除slf4j-log4j12,但仍然不能工作,每次都有警告 我找遍了所有的地方,但我无法移除警告。 有什么建议吗?

  • 我收到编译错误。我不确定是哪个依赖项提供了这个错误。我正在使用@slf4j lombok注释在我的类中实现日志记录。 SLF4J:类路径包含多个SLF4J绑定。slf4j:在[jar:file:/home/andrius/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.25/110cefe2df103412849d72e