0

I have an abstract class AbstractTimerTask that extends TimerTask and I have a Jersey service that is going to manage these timer tasks. I will have more than one implementation of the abstract class, and I would like them all injected into the service. If possible, I would like to be able to inject them into a list of type List<AbstractTimerTask>. It is possible that one or more of the child classes will not be available, depending on which jar files I deploy to the server. I would like only the child classes that are available to be injected. For this reason, I can't just list the classes in the service class as individual dependencies and build the list myself.

Is it possible to inject multiple classes with the same parent type into a list of that parent type?

BamaPookie
  • 2,560
  • 1
  • 16
  • 21
  • In particular hk2 was designed to work very well in situations where the child classes are added or removed at runtime. It allows for a very dynamic set of runtime services that can change during the lifetime of the JVM – jwells131313 Sep 18 '15 at 01:24

1 Answers1

3

You can inject IterableProvder<AbstractTimerTask>, as seen in this answer

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720