You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A while ago I asked a question (#8308) and I've finally figured out what's going on. The issue stems from placing a qualifier on a duplicated bean, and once this is done then attempting to retrieve it from outside of the "instance" will result in confusion (and the first copy always being returned).
@EachBean(MyConfig.class)
@Singleton
@MyQualifier
public class MyClass { /*snip*/ }
@Inject ApplicationContext ctx;
Collection<MyClass> copies = ctx.getBeansOfType(MyClass.class);
// Do something with copies, but only ever get 1 instance, regardless of the configuration
As a matter of habit I've been qualifying all beans I create as both a matter of safety (lessens the likelihood of a collision) and as an idea to indicate where the bean is expected to be used (i.e.: @ui bean should be used within the UI). I realize that the qualifier is somewhat useless for an @EachBean. but I was going under the assumption that the qualifier would simply be applied to all copies (which can safely be done if I manually create multiple copies as far as I know), and to be consistent with all beans across the board.
So for the million dollar question, the behavior I'm seeing when qualifying/annotating @EachBean... is this a bug, or am I doing something I shouldn't be doing?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
A while ago I asked a question (#8308) and I've finally figured out what's going on. The issue stems from placing a qualifier on a duplicated bean, and once this is done then attempting to retrieve it from outside of the "instance" will result in confusion (and the first copy always being returned).
As a matter of habit I've been qualifying all beans I create as both a matter of safety (lessens the likelihood of a collision) and as an idea to indicate where the bean is expected to be used (i.e.: @ui bean should be used within the UI). I realize that the qualifier is somewhat useless for an @EachBean. but I was going under the assumption that the qualifier would simply be applied to all copies (which can safely be done if I manually create multiple copies as far as I know), and to be consistent with all beans across the board.
So for the million dollar question, the behavior I'm seeing when qualifying/annotating @EachBean... is this a bug, or am I doing something I shouldn't be doing?
Beta Was this translation helpful? Give feedback.
All reactions