2

I have 3 server-mode (1,2,3) in a web application, for each server-mode a controller class with same path (/abc) is there.

ex: abc1.class, abc2.class, abc3.class and all the class inherits abc interface

Server mode will be decided on server startup by reading a conf file.

Q1. My problem is i can't remove those controller classes on build time. Now based on the server mode say 2 then instance of abc2 class should be point for the path /abc.

Q2. This is same for service classes(100+ similar service & controller class are there) as well. @Inject should get instance of abc, based on server mode.

I am new to jersey. what i learn is @Qualifier, @Priority, InjectionPoint but non of them suite my case (with my understanding)

My idea (for Q2) is to create a common layer(@CustomInject) to done this dependency injection,

By creating an annotation "ServerMode(value (1|2|3)" add them in those classes, based on the value/server-mode, instance of requested Class-Type can be returned from this common layer

(similar to inherit @inject & @any loop the available instance & then return desire one based on servermode from this common layer)

Is this possible? if so how to achieve it (for Q1 & Q2), any better predefined way/ annotation is there ?

thanks for you time & help

srihari92
  • 46
  • 5
  • If the different server mode classes are in different packages, you can just use Jersey's package scanning to scan the package of the right server mode – Paul Samsotha Aug 29 '20 at 00:32
  • @PaulSamsotha base packages are common, tried that but not suit my requirement. thanks for answer. – srihari92 Aug 29 '20 at 05:06
  • 1
    This is something you will have to do manually. Just create your own annotation and scan your resource classes and conditionally register them based on the annotation value. Check out [this library](https://stackoverflow.com/a/520339/2587435) for some help scanning. See example use [here](https://stackoverflow.com/a/52564924/2587435) where it scans looking for an annotation on a class. – Paul Samsotha Aug 31 '20 at 14:56

0 Answers0