spring boot 프로젝트의 WebFliter 테스트 코드를 작성하며 공부한 내용을 정리한다.번역은 훗날의 내가 이해할 수 있을 정도의 수준으로 해놨으므로 서치타고 들어온 방문객들은 원문을 읽기를 권장한다. 공식문서Spring Framework : WebFilter https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/server/WebFilter.htmlSpirng Framework : ServerWebExchange https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/server/Serv..
class MDCContext( val contextMap: MutableMap = MDC.getCopyOfContextMap(), key: CoroutineContext.Key) : ThreadContextElement, AbstractCoroutineContextElement(key) {key는 단지 AbstractCoroutineContextElement(key)에 넘겨주기 위한 용도로만 필요하지, 이 클래스 내부에서 사용할 필요가 없기 때문에 val을 붙이지 않은 것이다.
enum은 단순한 이름 상수(name constant)가 아니라, 각 상수마다 다른 데이터를 가질 수 있는 객체다.즉, 아래처럼 NAVER, KAKAO는 단순히 "naver"나 "kakao"라는 이름이 아니라, Partner라는 클래스의 인스턴스이고, 각각 다른 값을 갖는 객체다:enum class Partner(val value: String) { NAVER("naver"), KAKAO("kakao") } Kotlin의 enum class에서 value: String처럼 val 없이 생성자 매개변수만 선언할 때, 이런 단순 생성자 매개변수는 왜 존재하는가? 언제 쓰는가?내부 처리용 임시 매개변수로 사용하려는 경우에만 의미 있음즉, val이나 var 없이 생성자 매개변수를 선언하면, 그 값은 enum 상..
MDCContextclass MDCContext( val contextMap: MDCContextMap = MDC.getCopyOfContextMap()) : AbstractCoroutineContextElement, ThreadContextElementMDCContextMap> (source)MDC context element for CoroutineContext.Example:MDC.put("kotlin", "rocks") // Put a value into the MDC contextlaunch(MDCContext()) { logger.info { "..." } // The MDC context contains the mapping here}Note that you cannot upd..
Slf4j의 문제점아래는 로그 레벨을 Debug로 설정해뒀을 때만 출력되는 로그 예제이다.if (logger.isDebugEnabled()) { logger.debug("{}", foo.veryExpensiveMethod());}이렇게 작성하는 이유는 다음과 같다:foo.veryExpensiveMethod()는 실행 비용이 크다.isDebugEnabled() 조건문을 사용해서 로그 레벨이 DEBUG가 아니라면 호출을 막아 비용을 절감한다.하지만 매번 조건문을 작성해야 해서 보일러플레이트 코드가 발생한다. 람다(Supplier)를 이용한 개선 방식Java 8부터 도입된 람다를 사용하여 개선할 수 있다. 람다는 함수의 마지막 파라미터를 함수 본문으로 옮길 수 있기 때문인데...🔹 Supplier는 ..
In Spring WebFlux, a WebFilter is an interface used to intercept and process web requests and responses in a reactive manner. It provides a mechanism for implementing cross-cutting concerns, such as security, logging, or request/response manipulation, before the request reaches the target handler or after the handler has processed it. Interface Definition: The WebFilter interface defines a singl..