美文网首页
maven 解决引入jar冲突

maven 解决引入jar冲突

作者: simians | 来源:发表于2019-03-15 17:21 被阅读0次

在引入spring boot 依赖时默认依赖logback 而引入其webmagic 是默认依赖log4j
webmagic 是强制依赖log4j 所以修改一下spring boot 默认依赖
直接将logback 排除出依赖如下

        <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-log4j</artifactId>
        </dependency>

如果不加就会在启动时报如下错误:

SLF4J: Found binding in [jar:file:/D:/maven/maven-repertory/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/maven/maven-repertory/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.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.Log4jLoggerFactory]
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: 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.Log4jLoggerFactory loaded from file:/D:/maven/maven-repertory/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.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.Log4jLoggerFactory
    at org.springframework.util.Assert.instanceCheckFailed(Assert.java:655)
    at org.springframework.util.Assert.isInstanceOf(Assert.java:555)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:286)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:220)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:199)
    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:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)

相关文章

  • maven 解决引入jar冲突

    在引入spring boot 依赖时默认依赖logback 而引入其webmagic 是默认依赖log4jwebm...

  • swagger的使用

    一开始运行swagger时依赖包冲突,需要手动引入guava.jar的20.0版本 Maven依赖冲突的两种解决方...

  • 依赖冲突解决办法

    依赖冲突解决办法 maven 的价值 Java开发中,jar的管理由maven来管。maven做的事情: jar统...

  • Maven中依赖冲突解决方案

    在使用Maven中我们导入jar包坐标时会产生依赖传递,而依赖传递难免会发生jar包间的依赖冲突,解决jar包冲突...

  • Maven基础

    Maven介绍 可以管理项目jar包的构建,解决jar包之间的冲突;可以对项目进行管理,比如项目打包等,maven...

  • guava版本冲突解决办法--maven项目

    maven项目解决jar包冲突的四种方式 guava版本冲突解决办法 ------场景:grpc-all 和 es...

  • maven引入jar包冲突问题

    最近做的个项目要在原工程里引入个二方hqueue的jar包,包里用了hbase的包又引用了Guava11版本,但是...

  • Maven 依赖管理

    管理包依赖是 Maven 核心功能之一,下面通过如何引入 jar 包;如何解析 jar 包依赖;包冲突是如何产生;...

  • maven引入外部jar包

    springboot引入外部jar包 在maven中引入jar包 设置maven-build 在pom.xml中设置

  • maven 学习1

    什么是maven 在之前是使用下载jar包的形式,不方便管理jar包,而且容易冲突,需要定义相同的东西。 引入ma...

网友评论

      本文标题:maven 解决引入jar冲突

      本文链接:https://www.haomeiwen.com/subject/mbermqtx.html