반응형
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.

Spring Cloud Config Server 랑 Client 구성하다가 위와 같은 에러를 보게 되었다... 분명 라이브러리랑 맞게 들어간것 같은데.

gradle 에 설정된 dependency는 다음과 같이 정의 했다.

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-config-client'

우선 찾아보니 내가 bootstrap.yml을 로드하는 과정에서 문제가 있던 거였다. 다음과 같이  bootstrap.yml 을 정의해놨었다.

spring:
  application:
    name: myapp
  profiles:
    active:
      dev
  cloud:
    config:
      server:
        uri: http://localhost:8888

그런데 이걸 로드하기 위해서는 라이브러리가 추가로 필요했던 거였다.

To use the legacy bootstrap way of connecting to Config Server, bootstrap must be enabled via a property or the spring-cloud-starter-bootstrap starter.

(출처 : https://docs.spring.io/spring-cloud-config/docs/current/reference/html/)

위 글에서처럼 bootstrap 방법으로 Config Server 를 접근하기 위해서는 spring-cloud-starter-bootstrap 을 추가해줘야 한다고 되어있다. 그래서 다음과 같이 build.gradle 파일에 라이브러리를 추가했다.

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

그런데 위 글을 보면 뭔가 이상한 점이 있다. 잘 보면 legacy bootstrap way 라고 되어있다. 음.. legacy 라니. 그럼 이제는 이렇게 안써도 되는건가. 위 링크를 찾아가서 위로 살짝 올라가면 다음과 같은 글이 또 있다. 

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.
To optionally connect to config server set the following in application.properties:
application.propertiesspring.config.import=optional:configserver:
This will connect to the Config Server at the default location of "http://localhost:8888". Removing the optional: prefix will cause the Config Client to fail if it is unable to connect to Config Server. To change the location of Config Server either set spring.cloud.config.uri or add the url to the spring.config.import statement such as, spring.config.import=optional:configserver:http://myhost:8888. The location in the import property has precedence over the uri property.

정리하면 이렇다. 

1. bootstrap.yml 을 이용해서 Config Server 를 찾는 경우

  • spring-cloud-starter-bootstrap 라이브러리가 필요하다.
  • spring-cloud-starter-bootstrap 는 spring.cloud.bootstrap.enabled=true 로 설정하면서 bootstrap 에 정의 해놓은 spring.cloud.config.uri 를 통해 Config Server 를 찾는다.

2. bootstrap.yml 을 이용하지 않는 경우

  • application.yml 파일에  spring.config.import=optional:configserver 라고 정의를 하면 default 로 http://localhost:8888 주소로 Config Server 를 찾는다.
  • 주소를 변경하고 싶으면 spring.config.import=optional:configserver:http://host:port 로 정의해주면 된다.

그래서 난 2번 방법으로 application.yml 파일에 다음과 같이 정의했다.

spring:
  application:
    name: tuja
  profiles:
    active: dev
  config:
    import: optional:configserver:http://localhost:8888

 

728x90
반응형

+ Recent posts