mirec
mirec

Reputation: 656

spring-boot 2.5.5 property "spring.config.import" not defined?

after upgrade spring-boot:2.3.11.RELEASE to spring-boot:2.5.5 and spring-cloud:Hoxton.SR11 to spring-cloud:2020.0.4, spring-boot:run is failing with:

***************************
APPLICATION FAILED TO START
***************************

Description:

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.

Advices are pretty clear so I added

spring.cloud.config.enabled=false
spring.cloud.config.import-check.enabled=false
spring.config.import=optional:configserver:

to both application.properties and bootstrap.properties files

In application.properties I had to comment out line spring.config.import=optional:configserver: otherwise it failed with java.lang.IllegalStateException: Unable to load config data from 'optional:configserver:' ......... Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader

As I didn't need to comment it out in bootstrap.properties, values are ignored completely there probably

However application itself failed the same way as without any new properties added.

Any ideas what is the problem? What is correct format for spring.config.import=... ?

EDIT: after adding dependency

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

it doesn't ignore properties in bootstrap.properties anymore so I had to comment out "spring.config.import=optional:configserver:" there as well. However application still failing with "No spring.config.import property has been defined"

Upvotes: 2

Views: 19416

Answers (3)

Abrar Hussain
Abrar Hussain

Reputation: 35

Add this dependency

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

configuration

config:
  retry:
    initial-interval: 2000
    max-attempts: 10
  uri: http://localhost:8888
  fail-fast: false

and change application.yml to bootstrap.yml

Upvotes: 0

Tristate
Tristate

Reputation: 1831

In Spring Cloud 2020 you dont need the bootstrap.properties file anymore, importing spring-cloud-starter-bootstrap enable only a legacy way to use it. Just remove it...

You need to add

spring.config.import=optional:configserver:http://your.config.server.com

Into your application.properties. Howerver I am not sure what you are tring to achieve, because of your

spring.cloud.config.enabled=false

More Info

Upvotes: 2

Valdo
Valdo

Reputation: 1

It worked for me:

I'm using the version: <spring-cloud.version>2022.0.1</spring-cloud.version>

In an application.yaml file, I added the following:

server:
port: 8761
eureka:
client:
    register-with-eureka: false
    fetch-registry: false
spring:
cloud:
    config:
    enabled: false
application:
    name: eureka-server

In the POM:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>Greenwich.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

I got the solution here: https://www.baeldung.com/spring-cloud-netflix-eureka

Upvotes: 0

Related Questions