[英]Is there a Micronaut analogue for Spring @RequestScope?
Is there a @RequestScope
analogue in Micronaut? Micronaut中是否有@RequestScope
类似物?
If there are no equivalent annotations, how I can achieve the same effect in Micronaut? 如果没有等效的注释,如何在Micronaut中实现相同的效果?
I'm no Spring expert, but from what I understand there is nothing like @RequestScope in Micronaut. 我不是Spring专家,但据我了解,Micronaut中没有类似@RequestScope的东西。 However, u can set request scoped data using attributes on the current request via ServerRequestContext.currentRequest()
. 但是,您可以通过ServerRequestContext.currentRequest()
使用当前请求上的属性来设置请求范围的数据。
根据问题 ,该功能已计划
What do you need from the request scope in your context? 您需要从上下文中的请求范围中获得什么? If you need to access something like current HttpRequest
, try to use @ThreadLocal
-Scope. 如果您需要访问诸如当前HttpRequest
,请尝试使用@ThreadLocal
-Scope。 https://docs.micronaut.io/latest/api/io/micronaut/runtime/context/scope/ThreadLocal.html . https://docs.micronaut.io/latest/api/io/micronaut/runtime/context/scope/ThreadLocal.html 。 First, you need of course somehow to put current HttpRequest
into your ThreadLocal
. 首先,您当然需要以某种方式将当前的HttpRequest
放入您的ThreadLocal
。 Depending on your web framework it can be done with ie interceptors. 根据您的Web框架,可以使用拦截器来完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.