本地开发spark项目时,测试案例运行时出现以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.apache.spark.internal.Logging$class.initializeLogging(Logging.scala:111)
at org.apache.spark.internal.Logging$class.initializeLogIfNecessary(Logging.scala:102)
at org.apache.spark.SparkContext.initializeLogIfNecessary(SparkContext.scala:73)
at org.apache.spark.internal.Logging$class.log(Logging.scala:46)
at org.apache.spark.SparkContext.log(SparkContext.scala:73)
at org.apache.spark.internal.Logging$class.logInfo(Logging.scala:54)
at org.apache.spark.SparkContext.logInfo(SparkContext.scala:73)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:184)
at com.zofund.sparkcore.OnlineDemo$.main(OnlineDemo.scala:9)
at com.zofund.sparkcore.OnlineDemo.main(OnlineDemo.scala)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more
解决方法:
在项目的`pom.xml`文件中添加以下依赖:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
感谢以下两位的分享:
关于解决 java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder 的解决方法 - gongstring - ITeye博客文章来源:https://www.toymoban.com/news/detail-765534.html
java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder - san_yun - ITeye博客文章来源地址https://www.toymoban.com/news/detail-765534.html
到了这里,关于java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!