Spring Cloud Starter配置依赖关系导致ApplicationContextException

时间:2018-08-14 12:15:57

标签: java docker spring-boot spring-cloud spring-cloud-config

我试图将spring-cloud-starter-config依赖项添加到我的项目中(我已经启动并运行了spring配置服务器)。

compile('org.springframework.cloud:spring-cloud-starter-config')依赖项添加到build.gradle文件中后,我的应用程序将无法启动;而是抛出:

project_name      | org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
project_name      |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
project_name      |     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
project_name      |     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)

它在docker容器中运行,该docker文件如下:

FROM openjdk:8-jdk-alpine
ARG JAR_FILE
ADD ${JAR_FILE} /project-name.jar
ARG PROPS
ADD ${PROPS} /application.properties

# Expose web port
EXPOSE 8090
# Remote debugging port for intelliJ == address
EXPOSE 50505
ENTRYPOINT [ "java", "-Xrunjdwp:transport=dt_socket,address=50505,suspend=n,server=y", "-jar", \
"/project-name.jar", "--spring.config.location=file:/project-name/application.properties"]

还有build.gradle:

buildscript {
    ext {
        springBootVersion = '1.5.12.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.owasp:dependency-check-gradle:3.3.1'
    }
}

plugins {
    id 'de.aaschmid.cpd' version '1.1'
    id "com.github.johnrengelman.shadow" version "2.0.3"
}

group 'groupname'

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'cpd'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.owasp.dependencycheck'

sourceCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    //compile('org.springframework.boot:spring-boot-starter')
    compile("org.springframework.boot:spring-boot-starter-web")
    compile('org.springframework.cloud:spring-cloud-starter-config')

    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.8'
    compile 'org.elasticsearch:elasticsearch:5.6.8'
    compile 'org.elasticsearch:elasticsearch:5.6.8:javadoc'
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.8:javadoc'
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.8:sources'

    // https://mvnrepository.com/artifact/com.google.code.gson/gson
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'

    // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore-nio
    compile group: 'org.apache.httpcomponents', name: 'httpcore-nio', version: '4.4.9'

    // https://mvnrepository.com/artifact/javax.validation/validation-api
    compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'

    // https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.0.9.Final'

    // https://mvnrepository.com/artifact/commons-io/commons-io
    compile group: 'commons-io', name: 'commons-io', version: '2.6'

    // https://mvnrepository.com/artifact/commons-configuration/commons-configuration
    compile group: 'commons-configuration', name: 'commons-configuration', version: '1.10'

    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-configuration-processor
    compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '1.5.12.RELEASE'

    testCompile('org.springframework.boot:spring-boot-starter-test')

    // https://mvnrepository.com/artifact/org.mockito/mockito-all
    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'

    testCompile group: 'junit', name: 'junit', version: '4.12'
    // testCompile 'info.cukes:gherkin:2.12.2'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Edgware.SR4"
    }
}

repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
    maven {
        url 'https://repo.spring.io/libs-snapshot'
    }
}

jar {
    manifest {
        attributes(
                'Main-Class': 'com.altran.project.MainApplication'
        )
    }
}

shadowJar {
    // make more dynamic?
    baseName = 'project-name'
    archiveName = "${baseName}-${version}.${extension}"
}

有什么想法为什么这种春季云依赖会导致此问题?

0 个答案:

没有答案