我有Angular 5前端和Spring 5 REST后端的应用程序。我需要弹簧组件,它创建了一个令牌一次。如果我一直在使用非REST API,我可以使用@Scope("session")。但是现在每个请求的会话ID是不同的。
我需要它,因为中的java.security.Principal只提供用户名。但我需要按客户ID过滤我的实体。
我不想在每次请求时从数据库中获取客户。
发布于 2018-02-19 10:22:05
创建自己的作用域。将spring文档读到use a custom scope,或者访问Using custom scope 。你会发现很多例子,
创建一个实现作用域接口的类TokenScope,并像使用bean的任何其他作用域一样使用它。
对于一个典型的spring启动应用程序
@Qualifier
@Scope("token")
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface TokenScoped {
}并使用它。
@Component
@TokenScoped
class SomeBeanhttps://stackoverflow.com/questions/48858574
复制相似问题