0

Following this code:

@Component
public class ClassC extends ClassA<T> implements ClassB {

    private String preferredDateTimeFormat = null;

My process is using this class after calling a request from client.

Per each request I want to keep the preferredDateTimeFormat value, what is actually being made that, the preferredDateTimeFormat variable is being used for all of my requests.

What can I do to solve it?

roeygol
  • 4,908
  • 9
  • 51
  • 88

3 Answers3

1

Use @Scope on your class with value = request

like this

@Component
@Scope(value="request", proxyMode =ScopedProxyMode.TARGET_CLASS)
public class ClassC extends ClassA<T> implements ClassB {

  private String preferredDateTimeFormat = null;

You can find more information on Spring Bean Scopes here

fujy
  • 5,168
  • 5
  • 31
  • 50
  • That one worked, could you please give me some short info about the purpose of - `@Scope(value="request", proxyMode =ScopedProxyMode.TARGET_CLASS)` ? – roeygol May 10 '17 at 14:58
0

There are multiple ways.

You can define a Request Scope bean and place the preferredDateTimeFormat there.

OR

You can define ThreadLocal property and place the value there.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
0

I'm not entirely sure if you mean you want a ClassC instance per request or a new instance everytime it is used but you might want to look into the @Scope annotation with its values Prototype and Request.

See Spring Bean Scopes.

Community
  • 1
  • 1