【问题标题】:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementationLoggerFactory 不是 Logback LoggerContext 但 Logback 在类路径上。删除 Logback 或竞争实现
【发布时间】:2015-12-11 23:05:55
【问题描述】:

我尝试在 tomcat 服务器中启动我的 spring boot,但是当我向我的项目添加一些外部 jar 时:

appsert-rt.jar
gf-client.jar
javaee.jar

它给了我这个错误:

  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.JDK14LoggerFactory loaded from file:/C:/Users/amar/Documents/glassfish-3.1/glassfish/modules/bean-validator.jar). If you are using Weblogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.slf4j.impl.JDK14LoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext
        at org.springframework.util.Assert.isInstanceOf(Assert.java:339)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:151)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLogger(LogbackLoggingSystem.java:143)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:89)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartedEvent(LoggingApplicationListener.java:132)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:122)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
        at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
        at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:54)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:278)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)
        at demo.DemoApplication.main(DemoApplication.java:14)

我的 pom:

<?xml version="1.0" encoding="UTF-8"?>
     <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.udev</groupId>
    <artifactId>udev</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>demo.DemoApplication</start-class>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.6.4.RELEASE</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
         <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.14.8</version>
            <scope>provided</scope>
          </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
          </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

  </project>

注意:当我删除 jars 时它工作得很好/一个问题可能是我的 maven 添加的 jars 和外部添加的 slf4j 类之间的冲突

【问题讨论】:

  • 你有什么问题?
  • 我很困惑。您的问题说您正在 Tomcat 服务器中运行您的应用程序,但堆栈跟踪表明您正在通过 main 方法运行它。此外,异常消息表明您正在使用 Glassfish 3.1,或者至少是其中的一些 jar。您能否准确说明您是如何运行应用程序以及如何配置其类路径的?
  • 好吧,所以我在 glassfish 3.1 中部署了一个 EJB,我想从独立的客户端 sprint 引导中使用它,我必须主要包括 gf-client 到客户端类路径初始化上下文并执行查找
  • @reza 如何避免这个错误

标签: maven glassfish spring-boot


【解决方案1】:

在您的 Maven 项目中声明的 jar 与您显式导入的 jar 之间存在冲突。

依赖分析是使用像 Maven 这样的工具的一大好处,但它无法对手动添加运行时的依赖做任何事情。
您应该做的是将这些 jar 作为依赖项添加到您的 maven 项目中。一旦你这样做了,你可以使用 Maven 依赖插件来查找冲突的包,并为冲突的包添加排除项。

【讨论】:

    猜你喜欢
    • 2015-08-27
    • 2017-11-09
    • 1970-01-01
    • 2018-11-22
    • 2019-05-21
    • 2016-04-20
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多