• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

user-service에서 설정파일 정보를 읽어오지 못하고 있습니다.

23.05.01 15:44 작성 23.05.01 17:43 수정 조회수 917

0

현재 학습하고 있는 스프링 버전은 3.0.5 버전입니다.

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

위 두개의 라이브러리를 추가한 후

bootstrap.yml 파일을 생성해서 아래와 같이 작성을 하면

spring:
  cloud:
    config:
      uri: http://localhost:8888
      name: ecommerce

서버 실행 후 아래와 같이 로그가 출력됩니다.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.5)

2023-05-01T17:24:26.009+09:00  INFO 81323 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2023-05-01T17:24:26.117+09:00  INFO 81323 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=ecommerce, profiles=[default], label=null, version=6bb0cd579b695bb651be6edc215d85335734c939, state=null
2023-05-01T17:24:26.117+09:00  INFO 81323 --- [  restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-file:///Users/..../git-local-repo/ecommerce.yml'}]

name=ecommerce로 정상적으로 불러지고 있고, yml 파일 위치도 정상적으로 출력이 됩니다.
하지만 서버가 실행되다가 8888포트를 이미 사용을 하고 있다는 메시지와 함께 서버가 종료가 되었습니다.

검색을 해 보니 2.4버전대부터 설정하는 방법이 바뀌었다고 해서 변경된 방법으로 적용을 했습니다.


  1. bootstrap 라이브러리를 삭제했습니다.

implementation 'org.springframework.cloud:spring-cloud-starter-config'
  1. bootstrap.yml 파일을 삭제했습니다.

  2. application.yml 파일에 내용을 추가했습니다.

spring:
  config:
    name: ecommerce
    import: optional:configserver:http://localhost:8888

그리고 실행을 하면 아래와 같이 name=user-service로 적용이 됩니다.

2023-05-01T17:33:51.792+09:00  INFO 82127 --- [  restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : http://localhost:8888
2023-05-01T17:33:51.792+09:00  INFO 82127 --- [  restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=user-service, profiles=[default], label=null, version=6bb0cd579b695bb651be6edc215d85335734c939, state=null

이유가 application.yml 파일에서 config 설정 윗 부분에

spring:
  application:
    name: user-service

이렇게 application name을 설정을 해서 그렇게 나오는것 같습니다.

그리고 로그중에 아래와 같이 뜨는데

2023-05-01T17:33:51.793+09:00  INFO 82127 --- [  restartedMain] o.s.b.devtools.restart.ChangeableUrls    : The Class-Path manifest attribute in /Users/.../.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/4.0.1/bad26cea1d483dda57b6f634cdeaca3238637aea/jaxb-impl-4.0.1.jar referenced one or more files that do not exist: file:/Users/.../.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/4.0.1/bad26cea1d483dda57b6f634cdeaca3238637aea/jaxb-core.jar,file:/Users/.../.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/4.0.1/bad26cea1d483dda57b6f634cdeaca3238637aea/angus-activation.jar
2023-05-01T17:33:51.794+09:00  INFO 82127 --- [  restartedMain] o.s.b.devtools.restart.ChangeableUrls    : The Class-Path manifest attribute in /Users/.../.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/4.0.1/e8bf2d711d2d4250537199602bccae0cd4e62726/jaxb-core-4.0.1.jar referenced one or more files that do not exist: file:/Users/.../.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/4.0.1/e8bf2d711d2d4250537199602bccae0cd4e62726/jakarta.activation-api.jar,file:/Users/.../.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/4.0.1/e8bf2d711d2d4250537199602bccae0cd4e62726/jakarta.xml.bind-api.jar

아래의 라이브러리중 어떤것을 설치를 해도 똑같은 로그가 출력됩니다.
파일이 존재하지 않는다는 내용인데.. INFO레벨로 출력이 되서 우선은 그냥 넘어갔습니다.

	implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
//	implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4'

user-service를 실행을 시켜보면 아래와 같이 외부 설정 파일의 값을 읽어오지 못하고 있습니다.

It's Working in User Service, port(local.server.port)=56942, port(server.port)=0, token secret=null, token expiration time=null

아래의 공식 문서도 참고를 해 봤는데 어느 부분이 잘못됐는지 모르겠더라구요..
https://docs.spring.io/spring-cloud-config/docs/current/reference/html/

이 전단계의 git-local-repo 디렉토리를 만들어서 git을 commit까지 하는것은 정상적으로 됐고, 설정파일을 읽어오는것까지는 정상적으로 됐었습니다.

제 경우 한가지 이슈사항이 있던 부분은 git branch가 master로 되어있어서 오류가 나는 부분이 있어서 그 부분은 git branch를 main으로 하나 만들어서 적용을 하니 해당 오류는 해결이 됐었습니다.

 

최신 버전으로 적용을 할려고 하니 이리저리 쉽지가 않네요..

 

 

 

 

답변 2

·

답변을 작성해보세요.

0

김훈진 (KHJ)님의 프로필

김훈진 (KHJ)

2023.07.20

저도 님처럼 token secret랑 token expiration_time null로 받아와서 뭐가 문제지 한참 고민하다가
전 시간 강의에서 했던 config-service를 먼저 실행시키고 하니까 문제 없지 잘 실행되더라고요.
혹시 config-service를 실행시키지 않은 채로 user-service를 실행 시켜서 해당 문제가 발생하셨다면
config-service를 먼저 실행시킨뒤 user-service를 실행시켜 해당 작업을 다시 해 보시는 것이 어떠신가요?

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.05.24

안녕하세요, 인프런 AI 인턴이에요.

오류가 발생한 부분을 해결해보도록 하죠.
먼저, 구성 정보를 읽어오는 부분이 잘못된 것은 아닌지 확인해봐야겠습니다.
application.yml 파일 내용 중 profile 설정이 빠져 있는데, 이를 추가해주세요.

spring:
  profiles:
    active: default
  application:
    name: user-service
  cloud:
    config:
      uri: http://localhost:8888
      # profile 추가
      profile: default
      name: ecommerce

이어서 Pom.xml 파일에서 오타나 버전 관리가 어떻게 되어 있는지 확인해볼 필요도 있습니다.
오류 메시지에서 JAXB 라이브러리 관련 내용이 있으니, 관련 라이브러리로는 다음과 같이 설정해보세요.

<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-core</artifactId>
  <version>3.0.0-M1</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>3.0.0-M1</version>
</dependency>

오타와 버전 관리를 꼼꼼히 확인하면서 문제를 해결해보세요. 수고하세요!

질문 내용과 전혀 다른 답변을 AI가 해 주는데...ㅡ./,ㅡ