首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我将Spring的默认记录器更改为log4j2的尝试有什么问题呢?

我将Spring的默认记录器更改为log4j2的尝试有什么问题呢?
EN

Stack Overflow用户
提问于 2018-07-21 18:46:23
回答 1查看 5.7K关注 0票数 4

我是Spring的新手,我想将默认的记录器更改为log4j2,因为它的吞吐量比logback高。

这是我的格莱德尔剧本。如您所见,我正在使用Spring 2.0.3,并在之后禁用我使用的排除模块(logback和)的默认记录器。我正在脚本的底部编译log4j。

代码语言:javascript
复制
buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}



apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8



repositories {
    mavenCentral()
    jcenter()
}


ext {
    vaadinVersion = '8.4.1'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile('org.springframework.boot:spring-boot-starter-webflux')
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-log4j2')
    compile('com.vaadin:vaadin-spring-boot-starter')
    runtime('org.springframework.boot:spring-boot-devtools')
    compileOnly('org.springframework.boot:spring-boot-configuration-processor')
    compileOnly('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('io.projectreactor:reactor-test')
    testCompile('org.springframework.security:spring-security-test')
    testCompile 'junit:junit:4.12'


    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
    // https://mvnrepository.com/artifact/com.h2database/h2
    //compile group: 'com.h2database', name: 'h2', version: '1.0.60'
    testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'





}

dependencyManagement {
    imports {
        mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
    }
}

这是我的Spring应用程序。

代码语言:javascript
复制
package app.clothapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ClothappApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClothappApplication.class, args);
    }
}

但是,当我运行Spring应用程序时,它为我提供了一个AbstractMethodError。我读过其他一些这样的问题,而且很明显,自上次编译以来,某些类发生了不适当的变化。有人能提供帮助吗?

代码语言:javascript
复制
Exception in thread "main" java.lang.AbstractMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:472)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:442)
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:254)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:419)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
    at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
    at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
    at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
    at app.clothapp.ClothappApplication.main(ClothappApplication.java:10)

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-21 18:53:37

spring-boot-starter-logging上将有多个传递依赖项。例如:

  • spring-boot-starter-security依赖于spring-boot-starter
  • spring-boot-starter依赖于spring-boot-starter-logging

您可以运行gradle dependencies来确认。

为了从任何地方导出依赖关系,请使用:

代码语言:javascript
复制
configurations {
    all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}

春天的暗示包括对spring-boot-starter的依赖,然后将记录器排除在外,如下所示:

代码语言:javascript
复制
compile('org.springframework.boot:spring-boot-starter') {
    exclude module: "spring-boot-starter-logging"
}

但我发现并不是所有的Spring依赖关系都表现得那么好,所以当其他地方的Spring日志记录存在显式依赖时,上述方法有时会失败。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51459112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档