栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot引入海康CH-HCNetSDKV IllegalArgumentException: LoggerFactory is not a Logback LoggerContext

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot引入海康CH-HCNetSDKV IllegalArgumentException: LoggerFactory is not a Logback LoggerContext

SpringBoot引入海康CH-HCNetSDKV6.1.6.45 项目运行bug解决

bug产生原因添加Kotlin 相关依赖exclusion logback-classicexclusion logback-core项目成功运行!!

bug产生原因

开发中,遇到需要在项目中,引入海康开放平台demo,将代码及sdk全部引入后,pom.xml加上如下依赖。


     com.hikvision.ga
     artemis-http-client
     1.1.3

运行起来!!!
海康demo可以正常弹框如图。

但是,原来可以运行的项目不能正常启动了????
出现了下面的bug。。。。。

2022-02-27 15:53:06.317 [ INFO] [main] [org.springframework.core.KotlinDetector.(KotlinDetector.java:57)] - Kotlin reflection implementation not found at runtime, related features won't be available.
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.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/G:/maven/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory
	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:239)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:220)
	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.codvision.serverboot.ServerApplication.main(ServerApplication.java:21)
添加Kotlin 相关依赖

     org.jetbrains.kotlin
     kotlin-reflect
     1.6.10
     runtime
 

添加Kotlin依赖后,bug少了一个了!!!如图

exclusion logback-classic

bug中是这样写道的:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. 经过各种资料查询后,应该是海康demo中引用的日志依赖和我们原本项目中所应用的依赖不同导致的,可以这样解决下。
首先可以在pom.xml文件中右键,Maven–> Show Dependencies… 可以看到项目中依赖图。CTRL+F查找到logback-classic,移除该依赖属性。或可直接在pom中进行修改,如下。加入…部分内容。

  
            com.hikvision.ga
            artemis-http-client
            1.1.3
            
                
                    logback-classic
                    ch.qos.logback
                
            
        

再次运行项目,看能成功吗???
新的bug出现了。。。

Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.(LogbackLoggingSystem.java:73)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:168)
	at org.springframework.boot.logging.LoggingSystem.lambda$get$1(LoggingSystem.java:159)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet.lambda$entryConsumer$0(Collections.java:1577)
	at java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)
	at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntrySetSpliterator.tryAdvance(Collections.java:1596)
	at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
	at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
	at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:159)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:238)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:220)
	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.codvision.serverboot.ServerApplication.main(ServerApplication.java:21)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
	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)
	... 32 more

exclusion logback-core

这一次,只需在pom.xml中继续exclusion一次就可以了!!,加入如下代码,再次运行!

 

       ch.qos.logback
       logback-core

项目成功运行!!
	   
            com.hikvision.ga
            artemis-http-client
            1.1.3
            
                
                    logback-classic
                    ch.qos.logback
                
                
                ch.qos.logback
                logback-core
            
            
        
        
            org.jetbrains.kotlin
            kotlin-reflect
            1.6.10
            runtime
        

主要是pom.xml文件的配置,需要排除log的引入不同,需要添加的全部依赖,如上。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/750405.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号