0

java.lang.IllegalStateException: No thread-bound request found当我在我的 JPA 存储库类中使用 Javers 审计功能时,我得到了。

@JaversSpringDataAuditable

我的服务方法(创建/更新)@Async使用Future.

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

我在这里错过了什么吗?

java.util.concurrent.ExecutionException:java.lang.IllegalStateException:未找到线程绑定请求:您是指实际Web请求之外的请求属性,还是在原始接收线程之外处理请求?如果您实际上是在 Web 请求中操作并且仍然收到此消息,则您的代码可能在 DispatcherServlet/DispatcherPortlet 之外运行:在这种情况下,请使用 RequestContextListener 或 RequestContextFilter 来公开当前请求。在 java.util.concurrent.FutureTask.report(未知来源)~[na:1.8.0_112] 在 java.util.concurrent.FutureTask.get(未知来源)~[na:1.8.0_112]

原因:java.lang.IllegalStateException:未找到线程绑定请求:您是指实际 Web 请求之外的请求属性,还是在原始接收线程之外处理请求?如果您实际上是在 Web 请求中操作并且仍然收到此消息,则您的代码可能在 DispatcherServlet/DispatcherPortlet 之外运行:在这种情况下,请使用 RequestContextListener 或 RequestContextFilter 来公开当前 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] 在 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$ObjectFactoryDe​​legatingInvocationHandler.invoke(AutowireUtils.java:307 ) ~[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] 在 org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.applyVersionChange(JaversAuditableRepositoryAspect.java:94) ~[javers-spring-1.6.4.jar:na] 在 org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.applyVersionChanges(JaversAuditableRepositoryAspect.java:89) ~[javers-spring-1.6.4.jar:na] 在 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] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112] 在 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112] 在 sun。 reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_112] at java.lang.reflect.Method。调用(未知来源)~[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 ] 在 org.springframework.aop.aspectj.AspectJAfterReturningAdvice 的 org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE]。 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] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] 在 org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) [spring-aop-4.1.9 .RELEASE.jar:4.1.9.RELEASE] 在 com.vz.uiam.common.audit.aspect.JPAIdFieldNullifyAspect.monitor(JPAIdFieldNullifyAspect.java:55) ~[uiam_common_cloud-1.0.11.jar:1.0.11] 在太阳.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] 在 org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) [spring-aop-4.1.9.RELEASE.jar:4.1.9 .RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] 在 org.springframework.aop.interceptor。 ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) [spring-aop-4.1.9.RELEASE.jar:4.1.9.RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation。进行(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] 在 com.sun.proxy.$Proxy149.save(未知来源)~[na:na]

4

2 回答 2

0

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).

于 2017-04-25T17:31:51.443 回答
0

Nyamiou The Galeanthrope 给出的答案是正确的,但只是为了澄清:

com.vz.uiam.common.audit.javers.ServletRequestAuthorProvider 绝对不是 JaVers 类,而是 AuthorProvider 接口的一些实现。

默认情况下(如果您使用的是 spring-boot-starter-data-jpa),JaVers 会为您提供SpringSecurityAuthorProvider

于 2017-04-26T15:01:22.563 回答