在方面,我从下面的代码中获取HttpServletRequest HttpServletRequest请求=(((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()) .getRequest(); 然后我将其设置在某些请求范围Bean对象中,将其称为GlobalRequestObject。
现在,我将此请求范围bean对象传递给下面的方法
单身= Single.fromCallable(()-> { 返回GlobalRequestObject })。subscribeOn(Schedulers.from(customExecutor));
现在,当我尝试从GlobalRequestObject中获取标头时 GlobalRequestObject.getApiRequest()。getHeaderNames()我正在获取null( “ === MimeHeaders === \ n”)。
请问有什么机构可以帮助我解决这里的问题以及为什么标头会像在将请求传递给单个方法之前以null出现一样。
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Component
@Getter
@Setter
class GlobalRequestObject<<APIREQ> {
private APIREQ apiRequest;
}
@Component
@Aspect
public class Aspect{
@Around("executionOfPublicMethod()")
public Object proceed(ProceedingJoinPoint jp) throws Throwable {
Object result = null;
try {
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
GlobalRequestObject.setApiRequest((APIREQ) request);
result = jp.proceed();
} catch (Exception e) {
throw e;
} finally {
return result;
}
}