Loading...
Spring Framework Reference Documentation 7.0.2의 Attributes의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
요청에 attributes를 추가할 수 있습니다. 이는 filter 체인을 통해 정보를 전달하고, 특정 요청에 대해 filters의 동작에 영향을 주고자 할 때 유용합니다. 예를 들어:
1WebClient client = WebClient.builder() 2 .filter((request, next) -> { 3 Optional<Object> usr = request.attribute("myAttribute"); 4 // ... 5 }) 6 .build(); 7 8client.get().uri("https://example.org/") 9 .attribute("myAttribute", "...") 10 .retrieve() 11 .bodyToMono(Void.class); 12 13 }Copied!
1val client = WebClient.builder() 2 .filter { request, _ -> 3 val usr = request.attributes()["myAttribute"]; 4 // ... 5 } 6 .build() 7 8client.get().uri("https://example.org/") 9 .attribute("myAttribute", "...") 10 .retrieve() 11 .awaitBody<Unit>()Copied!
WebClient.Builder 레벨에서 전역적으로 defaultRequest 콜백을 구성할 수 있으며, 이를 통해 모든 요청에 attributes를 삽입할 수 있습니다. 이는 예를 들어 Spring MVC 애플리케이션에서 ThreadLocal 데이터를 기반으로 request attributes를 채우는 데 사용할 수 있습니다.
Filters
Context