No spring.config.import property has been defined

We Are Going To Discuss About No spring.config.import property has been defined. So lets Start this Article.

No spring.config.import property has been defined

How to solve No spring.config.import property has been defined

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.

No spring.config.import property has been defined

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.

Solution 1

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.

Original Author Dan Of This Content

Solution 2

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.

Original Author Taras Boychuk Of This Content

Solution 3

Root cause is Spring Boot 2.4 changed its default functionality. A new spring.config.import property is mandatory.

To fix, add the new spring.config.import property. Here is an example of what worked for me in application.yml.

spring:
  config:
    import: "optional:configserver:"

Here is the documentation in case you need to set a different value:

Spring Boot Config Data Import

Spring Boot 2.4 introduced a new way to import configuration data via the spring.config.import property. This is now the default way to bind to Config Server.

Original Author Justin Cranford Of This Content

Solution 4

Importing configuration since Spring Boot 2.4 is done by spring.config.import functionality.

Adding below to application.properties connects to the default config server URL http://localhost:8888.

spring.config.import=optional:configserver:

or yml:

spring.config.import: "optional:configserver:"

More configuration options are described in the reference documentation.

Legacy bootstrap functionality is still available if you add the org.springframework.cloud:spring-cloud-starter-bootstrap dependency to your project.

Original Author charlb Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment