jersey single path multiple class implementation (selecting one instance programatically) similary to conditional dependency injection

91 views Asked by At

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

0

There are 0 answers