简体   繁体   中英

java.lang.IllegalStateException: No thread-bound request found + @JaversSpringDataAuditable

I'm getting java.lang.IllegalStateException: No thread-bound request found , when I use Javers Audit feature in my JPA repository class.

@JaversSpringDataAuditable

My service method(create/Update) is defined with @Async and it's handled using Future .

Future<T> updateEmployee(Employee employee) {
    //some code here
    return new AsyncResult<T>(employeeDTO);
}

Am I missing anything here?

java.util.concurrent.ExecutionException: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at java.util.concurrent.FutureTask.report(Unknown Source) ~[na:1.8.0_112] at java.util.concurrent.FutureTask.get(Unknown Source) ~[na:1.8.0_112]

Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.at

org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.web.context.support.WebApplicationContextUtils.currentRequestAttributes(WebApplicationContextUtils.java:275) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.web.context.support.WebApplicationContextUtils.access$400(WebApplicationContextUtils.java:64) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:291) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:286) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:30 7) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE] at com.sun.proxy.$Proxy146.getHeader(Unknown Source) ~[na:na] at com.vz.uiam.common.audit.javers.ServletRequestAuthorProvider.provide(ServletRequestAuthorProvider.java:15) ~[uiam_common_cloud-1.0.11.jar:1.0.11] at org.javers.spring.auditable.aspect.OnSaveAuditChangeHandler.handle(OnSaveAuditChangeHandler.java:17) ~[javers-spring-1.6.4.jar:na] at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.applyVersionChange(JaversAuditableRepositoryAspect.java:94) ~[javers-spring-1.6.4.jar:na] at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.applyVersionChanges(JaversAuditableRepositoryAspect.java:89) ~[javers-spring-1.6.4.jar:na] at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.onVersionEvent(JaversAuditableRepositoryAspect.java:71) ~[javers-spring-1.6.4.jar:na] at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.onSaveExecuted(JaversAuditableRepositoryAspect.java:59) ~ [javers-spring-1.6.4.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_112] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.aspectj.AspectJAfterReturningAdvice.afterReturning(AspectJAfterReturningAdvice.java:61) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:53) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.sprin gframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at com.vz.uiam.common.audit.aspect.JPAIdFieldNullifyAspect.monitor(JPAIdFieldNullifyAspect.java:55) ~[uiam_common_cloud-1.0.11.jar:1.0.11] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_112] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod( AbstractAspectJAdvice.java:610) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] at com.sun.proxy.$Proxy149.save(Unknown Source) ~[na:na]

Javers is trying to find the author of the modification in the current web request. However, since you seems not to be in the context of a web request this fail.

If you are truly not in a web request, it seems you need to provide another AuthorProvider bean than ServletRequestAuthorProvider (which may be the default).

The answer given by Nyamiou The Galeanthrope is right, but just to clarify:

com.vz.uiam.common.audit.javers.ServletRequestAuthorProvider is definetly not a JaVers class but some implementation of the AuthorProvider interface.

By default (if you are using spring-boot-starter-data-jpa), JaVers gives you SpringSecurityAuthorProvider .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM