Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No spring.config.import property has been defined

While creating Spring Boot cloud config application getting below error. Any help on this?

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.
like image 432
Kamal Avatar asked May 12 '21 16:05

Kamal


2 Answers

Solution for Maven

Add the below dependency in the pom.xml file:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

Solution for Gradle

Add in the build.gradle file:

implementation('org.springframework.cloud:spring-cloud-starter-bootstrap')

That resolved my issue.

like image 107
Dan Avatar answered Oct 07 '22 17:10

Dan


You're getting this error because you're using a new version of Spring Boot and Spring Cloud, but you're trying to configure it in the old way.

The Reason

Spring Cloud Config Client has changed and technically bootstrap.properties and bootstrap.yml files are deprecated.

Correct Solution

  1. Move all properties from boostrap.properties to application.properties (it can be .yml as well)
  2. Remove bootstrap.properties file
  3. Replace spring.cloud.config.uri=http://localhost:8888 with spring.config.import=configserver:http://localhost:8888

This is a proper way to tell you Spring Boot app that you want to load properties from the Spring Cloud Config service that is running on localhost:8888.

Legacy Solution

In case you want to use a legacy bootstrap.properties file, you just need to add the following dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

Please note that this is a deprecated mechanism, so if you're creating a new project, go ahead with the correct solution.

like image 61
Taras Boychuk Avatar answered Oct 07 '22 17:10

Taras Boychuk