kyucumber
전체 글 보기

Kotlin 프로젝트의 Spring Boot 2.2.x 마이그레이션

운영중인 코틀린 프로젝트에서 Spring Cloud 관련 버전업이 필요한 부분이 있어 겸사겸사 2.1.x -> 2.2.x로 마이그레이션을 진행했습니다. 이후 마이그레이션 하는 경우에 활용하기 위해 마이그레이션 과정에서 겪었던 문제들을 아래에 정리했습니다.

Jackson module kotlin is prefix를 제거하는 버그 픽스

기존에 존재하던 is prefix를 제거하는 버그가 해소되었습니다. 아래와 같이 사용하는 코드가 있었다면 클라이언트쪽에서 찾아 변경하거나 @JsonProperty를 추가해 사용해야 합니다.

data class Data( val isAdmin: Boolean = false // is가 제거된 `admin`으로 Deserialize 되던 버그가 해결되어 이제 `isAdmin` 으로 Deserialize 된다. )

https://github.com/FasterXML/jackson-module-kotlin/issues/80

https://github.com/FasterXML/jackson-module-kotlin/issues/346

https://github.com/spinnaker/orca/commit/df71ed993f77b06b029f5e129256f1972d1d0d3b

Deprecated MediaType.APPLICATIONJSONUTF8

MediaType.APPLICATION_JSON_UTF8 가 Deprecate 되었습니다. 제기된 이슈와 관련된 내용을 살펴봤을 때 RFC 스펙이 변경되면서 JSON 인코딩이 기본적으로 UTF-8로 변경되었고 이에 따라 불필요해져 Deprecate 된 것 같습니다.

RFC-7159

JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32

RFC-8259

JSON text exchanged between systems that are not part of a closed ecosystem MUST be encoded using UTF-8

Deprecate 된 코드들만 제거해주면 큰 문제는 없었는데, 기존 MockMvc로 작성된 테스트 코드에서 한글이 다 깨지는 문제가 있었습니다. MockMvc를 사용하는 경우 아래처럼 DEFAULT_CHARACTER_ENCODING ISO_8859로 지정되어 한글이 깨지는 것 같네요.

public class MockHttpServletResponse implements HttpServletResponse { private static final String CHARSET_PREFIX = "charset="; private static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz"; private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); //--------------------------------------------------------------------- // ServletResponse properties //--------------------------------------------------------------------- private boolean outputStreamAccessAllowed = true; private boolean writerAccessAllowed = true; @Nullable private String characterEncoding = WebUtils.DEFAULT_CHARACTER_ENCODING; // public static final String DEFAULT_CHARACTER_ENCODING = "ISO-8859-1"; }

https://qastack.kr/programming/58525387/mockmvc-no-longer-handles-utf-8-characters-with-spring-boot-2-2-0-release

MockMvcSecurityAutoConfiguration 제거

아래 2.1.x에 있던 MockMvcSecurityAutoConfiguration가 제거되었습니다.

https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcSecurityAutoConfiguration.java

@Configuration @ConditionalOnProperty(prefix="spring.test.mockmvc", name="secure", havingValue="true", matchIfMissing=true) @Import(value={SecurityAutoConfiguration.class,UserDetailsServiceAutoConfiguration.class,org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration.class}) public class MockMvcSecurityAutoConfiguration {}

위 AutoConfiguration이 제거되면서 테스트 일부가 영향을 받아 실패했습니다. 변경된 AutoConfiguration에 따라 불필요한 exclude 설정을 정리해 깨진 테스트를 복구했습니다.

MockMvcSecurityAutoConfiguration이 제거되고 아래와 같이 변경되었습니다.

autoconfigure

# AutoConfigureMockMvc auto-configuration imports org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc=\ org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration,\ org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration,\ org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\ org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration

AntPathMatcher 우선순위 변경 관련 이슈

우선순위를 정하는 compare 로직에 아래 코드가 추가되었습니다. 큰 변경이 있었던 건 아니지만 기존 AntPathMatcher를 활용하던 프로젝트라면 원하던 대로 기존 로직들이 동작하는지 체크해보아야 할 것 같습니다.

if (info1.isPrefixPattern() && info2.isPrefixPattern()) { return info2.getLength() - info1.getLength(); }

https://github.com/spring-projects/spring-framework/blob/5.2.x/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java#L782

Tomcat 메트릭 노출 이슈

2.2.x로 마이그레이션을 진행한 이후 아래와 같은 톰캣 메트릭들이 노출되지 않았습니다.

tomcat_threads_busy_threads

릴리즈 노트를 제대로 보지 않아 해당 부분의 패치를 누락했습니다. 아래 설정을 추가해 해결할 수 있습니다.

server: tomcat: mbeanregistry: enabled: true

Spring Boot 2.2 릴리즈 노트 Tomcat’s MBean Registry

Tomcat’s MBean Registry is now disabled by default, saving approximately 2MB of heap. If you want to use Tomcat’s MBeans, for example so that they can be used to expose metrics via Micrometer, set the server.tomcat.mbeanregistry.enabled to true.

Redis cluster 사용 시 RedisReactiveHealthIndicator 이슈

2.2.x로 올리고 첫 배포를 진행할 때 레디스 클러스터를 사용중인 모듈의 헬스체크가 제대로 되지 않는 문제가 발생했습니다.

기존에 헬스 체크가 인프라에 영향을 받도록 구성되어 있었는데, 인프라 장애 시 어플리케이션 장애 대응이 더 어려워지는 문제가 있어 해당 부분을 제거했고, 이에 따라 헬스체크가 제대로 되지 않아 어플리케이션 배포가 되지 않는 문제도 자연스럽게 해소되었습니다.

https://github.com/spring-projects/spring-boot/issues/21514