-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider introducing @Eager or similar annotation for bean eager init #835
Comments
Agree this doesn't make much sense for other scopes than Another question: should this be limited to class-based beans? I guess producers and synthetic beans could benefit from this as well. |
It would seem odd if we used "eager" to mean "created at startup", rather than "created eagerly". I would expect an "eager" IIRC though, there's no requirement for scopes to have a defined beginning? |
My other thought is that, if eager initialization is only going to be used to run something at startup, then observing The only problem is when this startup logic is also some kind of initialization for your bean. Having it in |
Sure, but if we are talking an annotation, it doesn't make much sense as you won't execute anything and it will get destroyed immediately?
Hm, I assume the idea there is to pre-create beans that are time consuming to create on demand?
Yes, I thought about that as well but personally I find creating beans on scope/context start very awkward.
They are basically defined by firing an initialized event which you can observe. Can't think of anything else. |
I basically agree. Yet I keep hearing about Either way, I am not sold on this annotation either, I just want to create a tracking issue and see if there is any interest in it 🤷 |
Very much in support of this. I come across this repeatedly. People always miss the event observer. A simple annotation would greatly reduce ongoing confusion. |
+1 for |
I didn't follow up with the spec since while, but if its not there ( specially in the App scope and Singleton, as mentioned in one of the comments) it should be; in many designs we desire to fail early in case of mis-configuration or initialization problems than in th middle of a process that has customers engagement. There is alot to learn from the Servlets specs. |
This has been discussed and requested repeatedly (last I know of was here).
Note that this is not a new feature as the same can be achieved via declaration of
Startup
event observer in any given bean.However, that is often perceived as a workaround instead of a solution and is admittedly longer than using an annotation.
The idea would be to introduce an annotation such as
@Eager
/@Startup
(name is subject to change), declarable at bean class level, which would make CDI initialize the bean on container startup.Some thoughts:
@ApplicationScoped
(or@Singleton
) beans but can technically work for all scopesFTR, some discussion about implementation took place in the aforementioned issue (here). It boils down to:
Instance#get()
)toString()
which would work in 99% cases.The text was updated successfully, but these errors were encountered: