Unable to start spring boot server

前端 未结 9 1886
既然无缘
既然无缘 2020-12-29 03:51

I am new to spring boot and when I try to start my server , I get the following Exception. I understand that this has something to do with dependency conflict, but still una

相关标签:
9条回答
  • 2020-12-29 04:28

    In my project, it is using

    1. spring boot 1.4.2.RELEASE
    2. both slf4j 1.7.21 and logback 1.1.7. (some dependency , called module A, depend on logback 1.1.2, this is the issue)

    First Introduction to the Dependency Mechanism

    Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins. "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

    So maven will use logback 1.1.7 in my project. I am not sure it is my module A not compatible with 1.1.7 or logback 1.1.7 not compatible with slf4j 1.7.21 Whatever, in my case. I add dependencyManagement in my pom. Tell maven use lockback 1.1.2 only. Problem solved.

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.1.2</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>1.1.2</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-access</artifactId>
                <version>1.1.2</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    0 讨论(0)
  • 2020-12-29 04:33

    Add this to your build.gradle

    configurations.all {
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
            exclude group: 'org.springframework.boot', module: 'logback-classic'
    }
    
    0 讨论(0)
  • 2020-12-29 04:39

    I would recommend you to try removing any dependency that contains the Logback, the most common one is:

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

    It worked for me.

    0 讨论(0)
提交回复
热议问题