Java Magazine, Nov/Dec 2017
CDI 20 Making Dependency Injection a Lot Easier A new spec new features and new annotations whats not to like ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 23 java ee 8 Contexts and Dependency Injection CDI is Java EEs primary dependency injection framework It was introduced with Java EE 6 in 2009 Started by Gavin King of Hibernate fame and originally intended to unite the JavaServer Faces JSF and Enterprise JavaBeans EJB bean models CDI is now slowly but steadily becoming the backbone of all of Java EE JSF 23 for instance has fully deprecated its own managed bean model and dependency injection in favor of CDI while the new Java EE Security API has been designed specifically to work with CDI Interceptors and bean validation are usable without CDI but they are both easier to use with CDI Java EE 8 delivered a major update with CDI 20 Central to this update was splitting the spec into three parts the core spec Java SE features and Java EE features This division was done primarily to standardize how to use CDI in Java SE but it can also be seen as an attempt to make CDI a more core fundamental technology For instance the built in beans for Java EE which make for example the injection of HttpServletRequest or Principal possible could be moved to a more appropriate spec in Java EE without affecting the core part of the spec or the Java SE part of CDI In this article I demonstrate some of the most useful features in CDI 20 including Simplified programmatic creation of beans Programmatically adding an interceptor to a built in CDI bean Programmatic bean lookup simplifications There are some other interesting new features in CDI 20 such as event ordering and asynchronous events which will be covered in future articles in this magazine As you can tell if youve gotten this far this article is aimed at developers already familiar with Java EE and CDI ARJAN TIJMS
You must have JavaScript enabled to view digital editions.