Hi,
On Tue, Aug 25, 2015 at 7:20 PM, Nigel Deakin <nigel.deakin(a)oracle.com> wrote:
Someone over on the JMS user alias told me about this yesterday. So
that
would avoid the need to call a method to trigger lazy initialisation on
normal-scoped bean proxies. I presume the application still has to inject
the bean.
The bean does not necessarily have to be injected at any point.
With @Eager it will be activated and its @PostConstruct method will be
invoked in case it hadn't been referenced before (which in case of
@Eager is unlikely, as it instantiates very early, but still
theoretically possible).
The bean can of course still be injected or otherwise referenced later
within the same scope, but as mentioned this is not required.
So for example if you have OmniFaces on your classpath and then only
the following bean in an application:
@Eager
@ApplicationScoped
public class MyEagerApplicationScopedBean {
@PostConstruct
public void init() {
System.out.println("Application scoped init!");
}
}
Then you'll see "Application scoped init!" being printed in your
server log when you deploy that application. No other code is needed.
If so then it sounds useful. Is it going to be included as a
standard
feature of CDI 2.0? I see someone has proposed
https://issues.jboss.org/browse/CDI-473 .
As the issue already mentions, this is possible with current day CDI
already. The proposal may arguably make it a little more concise and a
little less verbose. An eager attribute on the scope looks like a
quite minimal and elegant solution. Additionally it may make sense for
some scopes to restrict for which "IDs' it's eagerly instantiated
(e.g. paths for @RequestScoped, view IDs for @ViewScoped, flow IDs for
@FlowScoped, etc).
A new @Startup seems more like a very specific usage of the eager
attribute, namely for @ApplicationScoped (or Singleton?) beans.
Kind regards,
Arjan
Nigel