我正在构建一个 API 并用于intercept(ApplicationCallPipeline.Call){}在每次路由执行之前运行一些逻辑。我需要将数据从拦截()方法传递到被调用的路由,并通过call.attributes.put()在拦截()中使用来设置数据,如下所示:
val userKey= AttributeKey<User>("userK")
call.attributes.put(userKey, userData)
并使用 检索userDatacall.attributes[userKey]。发生的情况是,这只call.attributes[userKey]适用于我设置属性的拦截()方法。它在我需要的路线上不起作用。它让我
java.lang.IllegalStateException: No instance for key AttributeKey: userK
我想知道我是否以正确的方式做事