TIL 2023.11.28 Spring 3.x.x Feign Client 적용

손창현·2023년 11월 29일
0

TIL

목록 보기
11/15

java 17, spring boot 3.2.0을 사용하면서 발생한 오류이다.

아래 사진은 Spring boot에 맞는 spring-cloud 버전을 보여준다. 오른쪽 Release Train 부분이 Spring boot 버전인데 본인은 spring boot 3.2.0 버전을 사용하고 있기 때문에 3.2.0 버전과 맞는 spring-cloud 버전을 찾을 수 가 없었다.

그래도 혹시 spring-cloud 2023.0.x 버전을 사용하면 되지 않을까 생각해 아래 사진을 참고해 spring cloud openfeign 버전을 4.1.0으로 설정해 보았다.

하지만 라이브러리를 가져오지 못하여 빌드가 진행되지 못했다.
현재 build.gradle에 아래와 같이 설정해두었다.

repositories {
    mavenCentral()
}

maven repository에서 central에서 가져오겠다는 의미같은데 아래 사진과 같이 central에서는 4.0.4 버전이 제일 최신 버전이기 때문에 4.1.0 버전의 openfeign을 가져오지 못하는 것 같다.

그래서 openfeign 4.0.x 버전을 모두 설정해 보았지만 아래와 같은 오류가 발생하였다.

Caused by: java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getTypeForFactoryBeanFromAttributes(FactoryBeanRegistrySupport.java:86)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:838)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:620)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:573)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:532)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:120)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:768)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:589)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:152)
	... 17 more

그래서 openfeign 3.x.x 버전을 설정해보았더니 4.0.x 버전와는 다르게 빌드엔 문제가 없었다. 하지만 또 다른 오류가 기다리고 있었다. 실제 런타임 시점에 feign client의 메서드를 사용해보니 아래와 같은 오류가 발생하였다.

jakarta.servlet.ServletException: Handler dispatch failed: java.lang.AbstractMethodError: Receiver class org.springframework.cloud.openfeign.support.SpringDecoder$FeignResponseAdapter does not define or inherit an implementation of the resolved method 'abstract org.springframework.http.HttpStatusCode getStatusCode()' of interface org.springframework.http.client.ClientHttpResponse.

결국 spring boot 버전은 3.1.x 로 낮추어 spring-cloud 2022.0.x의 openfeign 4.0.x 버전을 사용하기로 하였다.

정말로 spring boot 3.2.0 버전을 사용하여 openfeign을 사용하고 싶다면 아래 설정을 central이 아닌 spring milestones에서 가져오면 되지 않을까 생각한다.

repositories {
    mavenCentral()
}

profile
백엔드개발자 손창현입니다.

0개의 댓글