tag:blogger.com,1999:blog-8492059842142356488.post8065686077591148680..comments2023-09-23T16:46:57.616+02:00Comments on Thoughts on software development: Eager CDI beansOleg Varaksinhttp://www.blogger.com/profile/13872270134068047346noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-8492059842142356488.post-53254520701878039782016-02-10T21:35:00.358+01:002016-02-10T21:35:00.358+01:00public class MainClass {
public static void m...public class MainClass {<br /><br /> public static void main(final String... args) throws Exception {<br /> StartMain.main(args);<br /> }<br /><br /> public final void start(@Observes final ContainerInitialized event) throws Exception {<br /> System.out.println("Start...");<br /> }<br /><br />}<br /><br />public class AutoStart {<br /><br /> public void start(@Observes final ContainerInitialized event) {<br /> System.out.println("Hey I started.");<br /> }<br />}<br /><br />This should print <br />Start...<br />Hey I started.<br /><br />Thanks to Alessandro MattiuzziRadhakrishna Kalyanhttps://www.blogger.com/profile/08850715807658017832noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-62228228106058168532015-09-22T08:40:38.068+02:002015-09-22T08:40:38.068+02:00With @Observes the bean is created at startup too,...With @Observes the bean is created at startup too, also without Eager?Alexhttps://www.blogger.com/profile/06897096780214325264noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-62878534522901587632014-05-06T16:39:25.424+02:002014-05-06T16:39:25.424+02:00It annoys me this kind of very useful feature is n...It annoys me this kind of very useful feature is not out-of-the-box. What the hell? Are CDI creators idiots or what?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-60424000603116376302014-04-12T10:34:32.937+02:002014-04-12T10:34:32.937+02:00Great stuff thanks, it helped me a lot :-)Great stuff thanks, it helped me a lot :-)Anonymoushttps://www.blogger.com/profile/08292786015290362594noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-13013846550806978112013-12-01T00:52:21.146+01:002013-12-01T00:52:21.146+01:00Really good stuff here, Oleg and Thomas, and all t...Really good stuff here, Oleg and Thomas, and all that commented/responded! I didn't know about this blog until scouring OmniFaces issue list.<br /><br />OmniFaces issue 286: Add CDI compatible @Eager<br />https://code.google.com/p/omnifaces/issues/detail?id=286Howard Smithhttps://www.blogger.com/profile/01594886342056798831noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-14618158164801832772013-09-14T15:30:15.042+02:002013-09-14T15:30:15.042+02:00I just encountered a small issue with the extensio...I just encountered a small issue with the extension and that is that it gives the following error when a producer method is used. <br /><br />For instance:<br /><br />org.jboss.weld.exceptions.IllegalArgumentException: WELD-001305 The given type class org.wamblee.photos.model.plumbing.Producer is not a type of the bean Producer Method [Configuration] with qualifiers [@Eager @Any] declared as [[BackedAnnotatedMethod] @Produces @Eager @ApplicationScoped public org.wamblee.photos.model.plumbing.Producer.getConfiguration()]<br /><br /><br />In this case I defined a Producer class that has a producer method<br /><br /> @Produces<br /> @Eager<br /> @ApplicationScoped<br /> public Configuration getConfiguration() {...}<br /><br />The problem is that bean.getBeanClass() returns the class that contains the producer method (i.e. Producer) instead of configuration. <br /><br />I could solve this problem by using the following code instead to create the bean:<br /><br /> CreationalContext ctx = beanManager.createCreationalContext(bean);<br /> bean.create(ctx).toString();<br /><br />Nevertheless, I now see the bean being constructed twice. Once when I deploy the application (war) and once when it is injected for the first time into an object. Probably I am still not using the CDI API correctly. This happens both when I use the eager extension for a producer method or for a simple bean that is annotated with @Eager.<br /><br />Erik Brakkeehttps://www.blogger.com/profile/00016658868018858475noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-75518016876411327072013-06-03T17:11:39.475+02:002013-06-03T17:11:39.475+02:00Nice one Oleg! :)
Singleton beans ARE indeed an a...Nice one Oleg! :)<br /><br />Singleton beans ARE indeed an alternative, and they theoretically can be used in the front-end as pure front-end beans. They are part of the web profile and can be put in a .war.<br /><br />Historically EJBs were for back-end business logic only, but these days (again theoretically) they are just beans and a developer can decide for what purpose to use them.<br /><br />That said, practically speaking I see that many projects have the distinction EJB = business, CDI/JSF Managed beans = web/front-end. One must also take care that a Singleton comes with some baggage by default that might not be needed; every method acquires a lock AND starts a transaction. For many use cases in a web environment you would need to disable those. This makes an eagerly loaded CDI bean such as presented here a more natural solution.<br /><br />P.s.<br /><br />Regarding the deprecation; JSF managed beans are still not officially deprecated, not even in JSF 2.2. You could say though that they are effectively deprecated as of JSF 2.2. <br /><br />I hope JSF 2.3 will officially deprecate them and maybe start the Java EE pruning process even.<br />Arjan Tijmshttps://www.blogger.com/profile/08548593340781885396noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-34155032017181825362013-04-09T13:58:57.795+02:002013-04-09T13:58:57.795+02:00Just remove the @Qualifier from @Eager, this is no...Just remove the @Qualifier from @Eager, this is not required.Thomas Andraschkohttps://www.blogger.com/profile/17675421796799997447noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-19194803121253693742013-03-26T21:40:32.680+01:002013-03-26T21:40:32.680+01:00Oleg, in NetBeans 7.3, your code:
@Target({TYPE}...Oleg, in NetBeans 7.3, your code: <br /><br />@Target({TYPE}) <br /><br />causes this error: <br /><br />The CDI Annotation is declared as Qualifier but it has wrong target values. Correct target values are '{METHOD, FIELD, PARAMETER, TYPE'} or '{FIELD, PARAMETER'}.<br /><br />Do you have a fix or work-around?<br /><br />Thanks, Bill<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-90835649679798338792013-03-25T07:47:59.306+01:002013-03-25T07:47:59.306+01:00Your post is very informative, I appreciate you fo...Your post is very informative, I appreciate you for producing this great article, I want to say thanks to you for this awesome post.. <br />Harding Warrenhttp://grayburks.wordpress.com/2013/03/20/dont-consider-offshoring-software-development-for-the-purpose-of-solely-saving-money/noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-19798966568765273042013-02-26T11:47:13.165+01:002013-02-26T11:47:13.165+01:00I have been looking this type of information for a...I have been looking this type of information for a while because I am also working in <a href="http://www.goodcoresoft.com.my/" rel="nofollow">Software Development Company Malaysia</a>. I'd like to say thanks and want to say cheer!Anonymoushttps://www.blogger.com/profile/08022163110572472174noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-69895773854850688392013-02-19T20:47:03.570+01:002013-02-19T20:47:03.570+01:00Very good just the thing I was looking for a coupl...Very good just the thing I was looking for a couple of months ago.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-68621425929549089722013-02-19T17:18:14.473+01:002013-02-19T17:18:14.473+01:00As front-end developer I don't use EJBs. This ...As front-end developer I don't use EJBs. This is another layer.Oleg Varaksinhttps://www.blogger.com/profile/13872270134068047346noreply@blogger.comtag:blogger.com,1999:blog-8492059842142356488.post-26673031949689450392013-02-19T17:14:21.299+01:002013-02-19T17:14:21.299+01:00Hi Oleg,
just to understand: what's the advan...Hi Oleg,<br /><br />just to understand: what's the advantage over a Singleton Session Bean with the @Startup annotation? Since you're using JEE anyway...Anonymousnoreply@blogger.com