0

I am using J2EE with WASLiberty & Apache Wink (REST Impl). I would need in some cases to have api class to be singleton, however private constructor probably wont work with REST. Has anyone used api to be singleton ? any hints ?

To Kra
  • 3,344
  • 3
  • 38
  • 45

1 Answers1

0

As per Wink doc

The @Scope annotation According to the JAX-RS specification, by default, provider and resource classes are instantiated once for each JAX-RS application. This instantiation involves the default constructor for the class being called, with the injection of dependencies happening afterwards.

Since the instantiation of your resource class (in your words, API class) will be carried out by injection, I don't think the default ctor visibility will be an issue (In the worst case, make it public)

Shmil The Cat
  • 4,548
  • 2
  • 28
  • 37
  • Scope annotation is not part of JAX-RS spec, its wink specific I guess – To Kra Dec 02 '14 at 15:17
  • As per JAX-RS spec : "By default the life-cycle of root resource classes is per-request, namely that a new instance of a root resource class is created every time the request URI path matches the root resource." All the other annotations (such as @Singelton, @Scope) are JAX-RS *extensions* – Shmil The Cat Dec 02 '14 at 15:22
  • Btw. I just tried, and even using @Scope(ScopeType.SINGLETON), constructor has to be public :( don't like it – To Kra Dec 02 '14 at 15:38
  • public constructor is not exactly Singleton pattern :( – To Kra Dec 02 '14 at 17:30