Replies: 1 comment 1 reply
-
Have you considered using "Named" annotation ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a generic bean, where I am making a lot of instances for different types but I want the instance for each type to be a singleton. From my experimentation, if I annotate the class
@Singleton
, then only a single instance of the class is created and then reused for each subsequent instance (which is of course bad). If I annotate the class@Prototype
, then each type will receive its own instance... however a new instance is created even repeatedly injecting beans of the same type (which is not what I want).From my experimentation the only way I've been able to figure out to get around this would be to use a factory
or to subclass for each type. While both approaches are functional, it translates into a lot of boilerplate/repetitive code.
Is there a better way of achieving the same end result, and avoiding the repetition?
Beta Was this translation helpful? Give feedback.
All reactions