The log4j conflict problem encountered in the integration process of storm, hbase, and kafka

The log4j conflict problem encountered in the integration process of storm, hbase and kafka

---"Error
SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.
SLF4J: See also http: //www.slf4j.org/codes.html#log4jDelegationLoop for more details.

10059 [Thread-15-KafkaSpout] ERROR backtype.storm.util - Async loop died!
java.lang.NoClassDefFoundError: Could not initialize class org.apache. log4j.Log4jLoggerFactory
at org.apache.log4j.Logger.getLogger(Logger.java:39) ~[log4j-over-slf4j-1.6.6.jar:1.6.6]
at kafka.utils.Logging$class.logger(Logging .scala:24) ~[kafka_2.11-0.8.2.1.jar:na]

---" Reason
log4j-over-slf4j.jar AND slf4j-log4j12.jar The loop calls conflict, and the further reason is that in kafka and hbase Using log4j.

---"Solution

* Option 1: exclude the log4j-over-slf4j dependency in storm;
		<dependency>
			<groupId>org.apache.storm</groupId>
			<artifactId>storm-core</artifactId>
			<version>0.9.5</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
					<groupId>org.slf4j</groupId>
					<artifactId>log4j-over-slf4j</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
			     	
		<dependency>
			<groupId>org.apache.kafka</groupId>
			<artifactId>kafka_2.11</artifactId>
			<version>0.8.2.1</version>
		</dependency>
		
		<dependency>
			<groupId>org.apache.hbase</groupId>
			<artifactId>hbase-client</artifactId>
			<version>1.0.1.1</version>
		</dependency>


* Option 2: Exclude slf4j-log4j12 dependencies in kafka and hbase;

		<dependency>
			<groupId>org.apache.storm</groupId>
			<artifactId>storm-core</artifactId>
			<version>0.9.5</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>
			</exclusions>
			 -->
		</dependency>
			     	
		<dependency>
			<groupId>org.apache.kafka</groupId>
			<artifactId>kafka_2.11</artifactId>
			<version>0.8.2.1</version>
			<exclusions>
		        <exclusion>
		            <groupId>org.slf4j</groupId>
		            <artifactId>slf4j-log4j12</artifactId>
		        </exclusion>
		        <exclusion>
		            <groupId>log4j</groupId>
		            <artifactId>log4j</artifactId>
		        </exclusion>
		    </exclusions>
		</dependency>
		
		<dependency>
			<groupId>org.apache.hbase</groupId>
			<artifactId>hbase-client</artifactId>
			<version>1.0.1.1</version>
			<exclusions>
		        <exclusion>
		            <groupId>org.slf4j</groupId>
		            <artifactId>slf4j-log4j12</artifactId>
		        </exclusion>
		        <exclusion>
		            <groupId>log4j</groupId>
		            <artifactId>log4j</artifactId>
		        </exclusion>
		    </exclusions>			
		</dependency>
<!--
		<dependency>
			<groupId>org.apache.hbase</groupId>
			<artifactId>hbase-common</artifactId>
			<version>1.0.1.1</version>
		</dependency>
		 -->
		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
			<version>2.7.0</version>
		</dependency>


* Adopting scheme 2 is convenient for the cluster to publish
the logs of * storm using SLF4J and Logback log framework, so the storm code written by yourself uses the slf4j package uniformly, which can avoid most package conflicts.

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

public class MyBolt {
    private static final Logger LOG = LoggerFactory
            .getLogger(MyBolt.class);
}

---" Reference
http://www.tuicool.com/articles /aIzyqiy
http://stackoverflow.com/questions/21630860/storm-topology-not-submit
http://blog.csdn.net/gongmf/article/details/40379547

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326654962&siteId=291194637