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 ?
Asked
Active
Viewed 157 times
0
-
As you can see, I am using Apache Wink – To Kra Dec 02 '14 at 14:11
1 Answers
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
-
-
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
-