Skip to content

Spring Cloud Config: Resolving "No spring.config.import property" Error

Problem Statement

When working with Spring Boot and Spring Cloud Config, you may encounter the error:

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.

This error typically occurs in Spring Boot 2.4 and later versions when attempting to configure a Config Client application without properly using the new configuration import mechanism. The error indicates that Spring Cloud Config expects a specific property to be defined but cannot find it.

Root Cause

Starting with Spring Boot 2.4, the configuration loading mechanism was substantially changed. The legacy bootstrap.properties/bootstrap.yml approach was deprecated in favor of the new spring.config.import property. The error occurs when:

  1. Using newer Spring Boot/Cloud versions but configuring with the old bootstrap approach
  2. Missing the required spring.config.import property
  3. Having incorrect or incomplete Config Client configuration

Solutions

Primary Solution: Use spring.config.import Property

For Spring Boot 2.4+ applications, use the spring.config.import property in your application.properties or application.yml:

properties
spring.config.import=optional:configserver:http://localhost:8888
yaml
spring:
  config:
    import: "optional:configserver:http://localhost:8888"

The optional: prefix indicates that the application should start even if the Config Server is unreachable. If you require the Config Server to be available, use configserver: without the optional prefix.

Config Server Connection Details

To properly configure your Config Client, ensure you specify:

properties
spring.application.name=your-service-name
spring.config.import=optional:configserver:http://localhost:8888
yaml
spring:
  application:
    name: your-service-name
  config:
    import: "optional:configserver:http://localhost:8888"

Replace your-service-name with your actual service name and http://localhost:8888 with your Config Server's URL.

Legacy Bootstrap Approach (Deprecated)

If you need to maintain compatibility with legacy bootstrap configuration, add the bootstrap starter dependency:

xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
gradle
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'

Then you can use bootstrap.properties or bootstrap.yml:

properties
spring.application.name=your-service-name
spring.cloud.config.uri=http://localhost:8888
yaml
spring:
  application:
    name: your-service-name
  cloud:
    config:
      uri: http://localhost:8888

WARNING

The bootstrap approach is deprecated. Use the spring.config.import method for new projects.

Disable Config Client (For Testing)

If you don't need Config Server functionality during testing or development, you can disable it:

properties
spring.cloud.config.enabled=false
yaml
spring:
  cloud:
    config:
      enabled: false

Alternatively, disable just the import check:

properties
spring.cloud.config.import-check.enabled=false
yaml
spring:
  cloud:
    config:
      import-check:
        enabled: false

TIP

This approach is particularly useful for test configurations where you don't want to connect to a Config Server.

Complete Example

Here's a complete example of a properly configured Config Client:

yaml
spring:
  application:
    name: user-service
  config:
    import: "optional:configserver:http://localhost:8888"
  cloud:
    config:
      enabled: true
server:
  port: 8080
properties
spring.application.name=user-service
spring.config.import=optional:configserver:http://localhost:8888
spring.cloud.config.enabled=true
server.port=8080

Troubleshooting Tips

  1. Verify Spring Boot and Cloud Versions: Ensure compatibility between your Spring Boot and Spring Cloud versions
  2. Check Config Server Availability: Verify your Config Server is running and accessible
  3. Maven/Gradle Refresh: After adding dependencies, refresh your project (mvn clean install or Gradle sync)
  4. Check Property Placement: Ensure properties are in the correct configuration file (typically application.properties or application.yml)
  5. Verify Dependency Inclusion: Ensure you have the Spring Cloud Config Client dependency:
xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
gradle
implementation 'org.springframework.cloud:spring-cloud-starter-config'

Best Practices

  1. Use the latest configuration approach with spring.config.import for new projects
  2. Make Config Server connection optional in development using optional:configserver:
  3. Use proper error handling and fallback mechanisms for production environments
  4. Keep Spring Boot and Spring Cloud versions compatible
  5. Test configurations both with and without Config Server connection

By following these solutions and best practices, you can resolve the "No spring.config.import property" error and properly configure your Spring Cloud Config Client applications.