diff --git a/spring-graphql-docs/src/docs/asciidoc/index.adoc b/spring-graphql-docs/src/docs/asciidoc/index.adoc index 2d282d7d..eaac6bcb 100644 --- a/spring-graphql-docs/src/docs/asciidoc/index.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/index.adoc @@ -486,39 +486,40 @@ different thread. Spring for GraphQL supports propagating `ThreadLocal` values from the Servlet container thread to the thread a `DataFetcher` and other components invoked by GraphQL Java to -execute on. To do this, an application needs to create a `ThreadLocalAccessor` to extract -`ThreadLocal` values of interest: +execute on. To do this, an application needs to implement +`io.micrometer.context.ThreadLocalAccessor` for a `ThreadLocal` values of interest: [source,java,indent=0,subs="verbatim,quotes"] ---- -public class RequestAttributesAccessor implements ThreadLocalAccessor { +public class RequestAttributesAccessor implements ThreadLocalAccessor { - private static final String KEY = RequestAttributesAccessor.class.getName(); + @Override + public Object key() { + return RequestAttributesAccessor.class.getName(); + } - @Override - public void extractValues(Map container) { - container.put(KEY, RequestContextHolder.getRequestAttributes()); - } + @Override + public RequestAttributes getValue() { + return RequestContextHolder.getRequestAttributes(); + } - @Override - public void restoreValues(Map values) { - if (values.containsKey(KEY)) { - RequestContextHolder.setRequestAttributes((RequestAttributes) values.get(KEY)); - } - } + @Override + public void setValue(RequestAttributes attributes) { + RequestContextHolder.setRequestAttributes(attributes); + } - @Override - public void resetValues(Map values) { - RequestContextHolder.resetRequestAttributes(); - } + @Override + public void reset() { + RequestContextHolder.resetRequestAttributes(); + } } ---- -A `ThreadLocalAccessor` can be registered in the <> -builder. The Boot starter detects beans of this type and automatically registers them for -Spring MVC application, see the -{spring-boot-ref-docs}/web.html#web.graphql.transports.http-websocket[Web Endpoints] section. +You can register a `ThreadLocalAccessor` manually on startup with the global +`ContextRegistry` instance, which is accessible via +`io.micrometer.context.ContextRegistry#getInstance()`. You can also register it +automatically through the `java.util.ServiceLoader` mechanism. [[execution-context-webflux]]