我有一个2.0.1.RELEASE
使用 xs2 库 OAuth 2.0 安全性在 SCP 中运行的 Spring Boot 应用程序。如果我在 Postman 中创建访问令牌并直接调用我的 @RestController(到达数据库),我会从 TenantAccessor.getCurrentTenant() 收到此错误:
com.sap.cloud.sdk.cloudplatform.tenant.exception.TenantNotAvailableException: Failed to get current tenant: no request available. This error may occur when trying to obtain the current tenant within tasks that are not triggered by a request, for example, while using a RequestContextExecutor. Note that, on SCP CF, a request is required to obtain tenant information from the JWT bearer in the "Authorization" header.
我不明白为什么当我显然将带有包含不记名令牌的 Authorization 标头的请求直接发送到我的@RestController
.
我有一个想法通过用 注释TenantIdentifierResolver
类(包含 TenantAccessor)来解决这个问题@RequestScope
,但这失败了,因为在初始化应用程序时找不到请求上下文(entityManagerFactory
)。