Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to upgrade a project from SpringCloud BOM 2020.0.1 to 2020.0.2

When I change the BOM and re-build, I get an error in JUnit tests, saying that the new parameter spring.config.import is not set for configserver.

This project is not a ConfigServer, neither use ConfigServer (commented config client)

This is the reported error in tests contextLoads()

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
    .. Many more
Caused by: org.springframework.cloud.config.client.ConfigServerConfigDataMissingEnvironmentPostProcessor$ImportException: No spring.config.import set
    at org.springframework.cloud.config.client.ConfigServerConfigDataMissingEnvironmentPostProcessor.postProcessEnvironment(ConfigServerConfigDataMissingEnvironmentPostProcessor.java:60)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
    ... Many more

This is my build.gradle

plugins {
    id 'org.springframework.boot' version '2.4.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
group = 'com.example.microservices.composite.product'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
    mavenCentral()
    maven {
        url 'https://repo.spring.io/milestone'
ext {
   // resilience4jVersion = "1.7.0"
   resilience4jVersion = "1.6.1"
dependencies {
    // Local projects dependencies
    implementation project(':api')
    implementation project(':util') 
    // Implementations dependencies
    // Standard (actuator - for monitoring and Health)  
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    // WebFlux (asynchronous Web)
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    // SpringFox dependencies
    implementation "io.springfox:springfox-boot-starter:3+"
    implementation('io.springfox:springfox-spring-webflux:3+')
    // Implementation: Spring cloud
    implementation('org.springframework.cloud:spring-cloud-starter-config')
    implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
    implementation('org.springframework.cloud:spring-cloud-starter-stream-kafka')
    // Security
    implementation('org.springframework.boot:spring-boot-starter-security')
    implementation('org.springframework.security:spring-security-oauth2-resource-server')
    implementation('org.springframework.security:spring-security-oauth2-jose')
    // CircuitBreaker with Resilience4J
    implementation("io.github.resilience4j:resilience4j-spring-boot2:${resilience4jVersion}")
    implementation("io.github.resilience4j:resilience4j-reactor:${resilience4jVersion}")
    // Implementation: Tracing
    implementation('org.springframework.cloud:spring-cloud-starter-sleuth') 
    // Implementation: Performance metrics
    implementation("io.micrometer:micrometer-registry-prometheus")
    // TEST dependencies
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation('org.springframework.cloud:spring-cloud-stream-test-support')
dependencyManagement {
    imports {
        // mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.1'
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:2020.0.2"
test {
    useJUnitPlatform()

And my contextLoads() method in test class is trivial

// Test: Application
@AutoConfigureWebTestClient
@SpringBootTest(
    webEnvironment = WebEnvironment.RANDOM_PORT, 
    classes = { 
        ProductCompositeServiceApplication.class,
        TestSecurityConfig.class }, 
    properties = { 
        "spring.main.allow-bean-definition-overriding=true" })
    @Test
    public void contextLoads() {

NOTE: I have also tried defining the `spring.config.import' property to empty or none in the class, with no change

@SpringBootTest(
    webEnvironment = WebEnvironment.RANDOM_PORT, 
    classes = { 
        ProductCompositeServiceApplication.class,
        TestSecurityConfig.class }, 
    properties = { 
        "spring.main.allow-bean-definition-overriding=true",
        "spring.config.import=" })
                I have already included the logs (test report). Remember that the fail is during gradle build, in test phase, no running the program.
– Sourcerer
                Mar 27, 2021 at 15:49

I've faced same issue and resolved by adding bootstrap lib with config lib as follows,

implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'

I have noted the same problem after upgrading to SpringCloud 2020.0.2

Adding spring.cloud.config.enabled=false in the tests solved the issue.

E.g.:

@SpringBootTest(
  webEnvironment = RANDOM_PORT, 
  properties = {"spring.cloud.config.enabled=false"}
                Thank you very much, Magnus (and congrats for the book!). I have tried, and this solve the problem with test phase, but now fail the main program.  APPLICATION FAILED TO START *************************** No spring.config.import property has been defined  Action:  Add a spring.config.import=configserver: property to your configuration.         If configuration is not required add spring.config.import=optional:configserver: instead.         To disable this check, set spring.cloud.config.enabled=false or          spring.cloud.config.import-check.enabled=false.
– Sourcerer
                Mar 30, 2021 at 8:13
                It seems that the springfox project add a dependency with spring-cloud-starter-config, and the config client now has this behaviour. I have added the property to the application.yml for all chapters where config server is not used.
– Sourcerer
                Mar 30, 2021 at 9:49
<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

You can disable the import checks by adding these lines to your application.yml file in the test/resources folder:

spring:
  cloud:
    config:
       import-check:
          enabled: false
<dependency>
    <groupId>org.spring framework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
                Welcome to SO! Please note, that this answer has already been given by some of the other posters. In order to keep the site clean and make it easy to find answers, we try to avoid double answers.
– ahuemmer
                Aug 2, 2022 at 6:23
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.