Spring Boot starts slf4j and prompts that weblogic.xml cannot be found. Log exception

When starting a Spring Boot project, you will encounter the following log exceptions related to slf4j, causing the project to fail to start.

The related exception information is as follows:

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.slf4j.impl.Log4jLoggerFactory loaded from file:~/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.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:696)
	at org.springframework.util.Assert.isInstanceOf(Assert.java:596)

Obviously, the so-called weblogic.xml is not used in the project, so how come an exception regarding the configuration of WEB-INF/weblogic.xml is reported?

The key additions are here:

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation……

That is to say, Logback already exists in the classpath, but LoggerFactory is not the content of the online log related to Logback. At this point, you should be aware of the Logback dependency conflict.

At this point, you can check the maven dependencies to troubleshoot the problem, and execute the following commands in the project and directory:

mvn dependency:tree

The contents of the display results are as follows:

[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.1.5:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.1.5:compile
[INFO] |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile
[INFO] |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.5:compile
[INFO] |  +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.16:compile
...
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.5:compile

Obviously, it can be seen that the same slf4j-api jar package is referenced in multiple places. That is, the jar package conflicts. At this time, the dependent jar package is excluded, and there is only one place.

If the jar package in springboot is invalid, you can use the following methods to exclude:

<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>

If the jar packages of other dependent libraries are invalid, they can be excluded in the same way:

<dependency>
	<groupId>com.github.secbr</groupId>
	<artifactId>fastdfs-client-plus</artifactId>
	<version>1.1.1-RELEASE</version>
	<exclusions>
		<exclusion>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</exclusion>
	</exclusions>
</dependency>

Then restart the springboot project, the project can start normally.

Original link: " Spring Boot start slf4j prompts that weblogic.xml log exception is not found "

Fine SpringBoot 2.x video tutorial

"Spring Boot 2.x Video Tutorial Family Bucket" , a boutique Spring Boot 2.x video tutorial, to create the most complete set of Spring Boot 2.x video tutorials.


New Vision of Procedure

The public account " New Vision of Program ", a platform that allows you to simultaneously improve your soft power and hard technology, providing massive amounts of data

WeChat Official Account: New Vision of Program

Guess you like

Origin blog.csdn.net/wo541075754/article/details/107759787