Review: JBoss Weld CDI for Java Platform

6 min read
Some days ago some friends of mine asked me to review their trainee Java EE project. They decided to use Plain Old Tomcat with JSF and Hibernate running on Odroid-w.
Although the Plain Old Tomcat way with JSF and Hibernate is a minimalistic one, in my opinion it is too oldschool and I wanted to introduce another more appropriate and also minimalistic way to improve the code and also the programming model with Dependency Injection and some other features. Therefore I decided to add CDI to their Tomcat 7 application and deepen my knowledge about CDI and especially about Contexts at the same time by reading this book.


CDI simplifies dependency injection for modern application developers by taking advantage of Java annotations and moving away from complex XML, while at the same time providing an extensible and powerful programming model.
"JBoss Weld CDI for Java Platform" is a practical guide to CDI's dependency injection concepts using clear and easy-to-follow examples. This will help you take advantage of the power behind CDI, as well as providing a firm understanding of how to use it within your applications.
"JBoss Weld CDI for Java Platform" covers all the major aspects of CDI, breaking it down into understandable pieces. This book will take you through many examples of how these concepts can be utilized, helping you get up and running quickly and painlessly.
"JBoss Weld CDI for Java Platform" gives you an insight into the different scopes provided by CDI and the use cases for which each has been designed. You will learn everything about dependency injection, scopes, events, producers, and more from JBoss Weld CDI, as well as how producers can create new beans for consumption within your application. You will also learn how to build a real world application with CDI using JSF and AngularJS for different web interfaces.

Product Details

Paperback: 122 pages
Publisher: Packt Publishing (July 12, 2013)
Language: English
ISBN-10: 1782160183
ISBN-13: 978-1782160182

The Author

Ken Finnigan (@kenfinnigan) is a Principal Software Engineer at Red Hat, technical lead of the JBoss Portlet Bridge project, a member of the GateIn development team, and the founder of the Arquillian Portal Extension. As a consultant and engineer he has over 15 years development experience with enterprises throughout the world using technologies that include Java EE frameworks (JSF, CDI, EJB3, Hibernate, and Seam), Java testing frameworks (Arquillian, JUnit, and TestNG), Maven, Ant, and a variety of others. In his spare time, he is a committer for Apache DeltaSpike, ShrinkWrap, and Arquillian. He is also the author of GateIn Cookbook, Packt Publishing which is available here.


Chapter 1, What is a Bean?, provides an overview of CDI beans and their history, before explaining how a Java class can be a bean.
Chapter 2, Dependency Injection and Lookup, explains injection and lookup functions, by unterstanding qualifiers and injection points. We also cover some possible Weld dependency errors and how our beans are proxied.
Chapter 3, Deploying JBoss Weld, covers how to deploy JBoss Weld on JBoss AS, Glassfish and Tomcat
Chapter 4, Scopes and Contexts, explains the Scopes that are injecting into producer methods. We also explain pseudo scopes and creating a custom scope.
Chapter 5, Producers, covers producer methods and fields, injection into producer methods, and how we can clean up beans that we produce.
Chapter 6, Interceptors and Decorators, explains how to create and enable an interceptor, and how their bindings are  defined. We also look at enabling decoraters and what is a decorator delegate.
Chapter 7, Events, explains how to listen for and fire events, and what type of payload can be sent. We also explain advanced event qualifiers and how to listen for events during specific transaction phases.
Chapter 8, Writing a Portable Extension, explains how to create an extension to CDI and what events the container fires that we can utilize. We then cover some examples of what can be achieved within an extension.
Chapter 9, Book Store - CDI Services, covers the development of CDI Services, REST endpoints, and communicating with a database for our example application.
Chapter 10, Book Store - User Interfaces, explains how to develop a JSF admin interface and a user interface using AngularJS for our example application that will interact with our services.

Analysis of Content

The book starts with an introduction to Beans in Java and a brief overview about the CDI features covered in the following chapters.
The next chapters is about an well written introduction to Dependency Injection.
After this introduction Finnigan explains how to use JBoss Weld in the most used Java EE Application Server.
The following chapters give a background about CDI features like Scopes and Contexts, Producers, Interceptors, Decorators and Events. It also explaines how to write a portable CDI Extension.
Finally, the last two chapters illustrate the practical usage of CDI in an real world book store application with JSF, REST and AngularJS.

All chapters are clearly written and can easily be understood by non-natives.

There are also lots of tips and notes about the usage of these CDI features. I really like these blocks in Packt Publishing Books.

Conclusion and Recommendation

I read a lot about CDI and I can say this is the best source about CDI I have read so far.
It offers you a solid background about all the concepts of CDI.
What I really like is the introduction about Java Beans. In comparison to Oracle's JavaFX description of Java Beans this one explains it in a very clear way.
It also offers some good examples about the practical use of CDI in a Java EE web application with JSF, REST and AngularJS.

Brief Summary

If you are a CDI beginner and want to get started quickly with CDI, you will have lots of fun with this book. It guides you from the beginning with an installation of CDI over all the CDI features and ends with the practical usage in an example application.

PS: Although this book covers CDI 1.1 on JBoss AS 7, Glassfish and Tomcat 7 it is still usable with Wildfly 9, Glassfish 4.1 and Tomcat 8. You should not avoid it just because it covers an older version of CDI. However you should take at to be up to date. With CDI 1.2 for example the beans.xml became optional and there will be lots of other features and improvements with CDI 2.0.

Be Social, Share!