Spring Boot ignoring logback-spring.xml

前端 未结 6 481
慢半拍i
慢半拍i 2021-02-05 16:31

I have 2 Spring Boot (1.4.1-RELEASE) console applications using Logback. Both configuration files are more or less identical, are located in my /src/main/resources

6条回答
  •  不思量自难忘°
    2021-02-05 16:48

    Ok.

    I know this is a maven question. But you can 'translate' gradle talk into maven.

    The gist of the idea is:

    In my root build.gradle file.

    I had to exclude these items. The way gradle does it, is this is a "global to this project" type of exclude, so it gets them ALL in one place. But you can do the same "excluding"/scrubbing in maven, it will just look different. The groupid/artifactid's are what is important.

    allprojects {
    
    
        configurations {
         
            all {
                exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
                exclude group: 'org.springframework.boot', module: 'spring-boot-starter-log4j2'
            }
        }
    
    
    }
    

    Then in my (top layer) build.gradle (I don't have a monolith, I have a project with multiple modules). I added these dependencies:

    implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackClassicVersion
        
    implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
    

    My variable values for the two versions happen to be (at this time of writing this post)

        slf4jVersion = "1.7.30"
        logbackClassicVersion = '1.2.3'
    

    How do you find the 2 versions that play nice together?

    For example, if you look at:

    https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3

    and find the "compile dependencies", you'll see that

    logback-classic/1.2.3

    has

    org.slf4j » slf4j-api 1.7.25 1.7.30

    so somewhere between 1.7.25 and 1.7.30 will play nice with logback-classic/1.2.3

    There's probably a better way, but that's how I "get close" at the dependency game.

        slf4jVersion = "1.7.30"
        logbackClassicVersion = '1.2.3'
    

    But you would be better going to maven repostitory or jcenter and finding latest version but also versions that of these 2 things that play nice with each other.

提交回复
热议问题