Closed as not planned
Closed as not planned
Description
In Spring MVC, objects like RequestAttributes
and LocaleContext
are stored in threadlocal(RequestContextHolder
, LocaleContextHolder
).
To support propagation between threadlocal and reactor operation chain, e.g. using WebClient
in MVC, I have custom ThreadLocalAccessor
(from micrometer context-propagation) implementations for them.
However, it would be more useful if Spring Framework provided them.
Sample Implementations:
public class LocaleContextThreadLocalAccessor implements ThreadLocalAccessor<LocaleContext> {
static final String KEY = "my-locale-context";
@Override
public Object key() {
return KEY;
}
@Override
public LocaleContext getValue() {
return LocaleContextHolder.getLocaleContext();
}
@Override
public void setValue(LocaleContext value) {
LocaleContextHolder.setLocaleContext(value);
}
@Override
public void setValue() {
LocaleContextHolder.resetLocaleContext();
}
}
public class RequestAttributesThreadLocalAccessor implements ThreadLocalAccessor<RequestAttributes> {
static final String KEY = "my-request-attributes";
@Override
public Object key() {
return KEY;
}
@Override
public RequestAttributes getValue() {
return RequestContextHolder.getRequestAttributes();
}
@Override
public void setValue(RequestAttributes value) {
RequestContextHolder.setRequestAttributes(value);
}
@Override
public void setValue() {
RequestContextHolder.resetRequestAttributes();
}
}