遵循以下代码:
@Component
public class ClassC extends ClassA<T> implements ClassB {
private String preferredDateTimeFormat = null;
我的进程在调用来自客户端的请求后使用此类。
根据每个请求,我想保留preferredDateTimeFormat
值,实际上是什么,preferredDateTimeFormat
变量用于我的所有请求。
我能做些什么来解决它?
答案 0 :(得分:1)
在您的课程中使用@Scope
,其值为request
@Component
@Scope(value="request", proxyMode =ScopedProxyMode.TARGET_CLASS)
public class ClassC extends ClassA<T> implements ClassB {
private String preferredDateTimeFormat = null;
您可以在Spring Bean Scope here
中找到更多信息答案 1 :(得分:0)
有多种方式。
您可以定义一个Request Scope bean并将preferredDateTimeFormat
放在那里。
OR
您可以定义ThreadLocal属性并将值放在那里。
答案 2 :(得分:0)
我不完全确定您是否想要每次请求一个ClassC实例或每次使用新实例但您可能希望查看@Scope
注释及其值Prototype
和Request
。