Introducing Jakarta EE CDIContexts and Dependency Injection for Enterprise Java Development
ISBN 978-1-4842-5641-1e-ISBN 978-1-4842-5642-8
© Luqman Saeed 2020
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail firstname.lastname@example.org, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Thank you for picking upIntroducing Jakarta EE CDI: Contexts and Dependency Injection for Enterprise Java Development. I wrote this book as a response to the lack of easy-to-understand books on using the compelling and intuitive Contexts and Dependency Injection API on the Jakarta EE (formerly Java EE) platform.
This book covers the very essentials of the CDI API and aims at explaining the various constructs in a way that is easy to understand and relate to. The ultimate goal is to help you, the everyday Java developer, write better code. Throughout the book, you will be working on a simple restaurant application, seeing when and how the various CDI API constructs can be used.
What Do You Need to Know to Use This Book?
Ideally, you should be a Java developer who is comfortable with Java SE before starting with this book. Knowing a bit of Java EE or Spring should help you pick up the concepts faster, but isn’t required. You should also have at least Java 8 installed on your machine.
What Does the Book Cover?
The book starts with the theory of Java EE, including its evolution to present-day Jakarta EE, and proceeds to cover CDI, starting with how to activate it explicitly. The discussion then builds on the concept of CDI beans and discusses the various types. You then learn about CDI contexts and injection points. The book then introduces CDI qualifiers, producers, interceptors, and finally CDI events.
What Will You Learn in the End?
This is a very concise book that covers only what matters. Your time is important, so I selected topics that I use personally in my day-to-day coding. There is no point in loading the book with topics you will only use sparingly. So this book should be straightforward to consume over a weekend.
At the end of this book, you will have a firm grasp of the Contexts and Dependency Injection API. You’ll know what it is, when to use it, and how to write better, more readable and maintainable code with it.
Where Is the Source Code?
The entire code for the book is available on GitHub, both in an Apress branded repo located at www.github.com/apress/introducing-jakarta-ee-cdi and on my own repo, located at https://github.com/pedanticdev/jee-book . The project is built with the Maven dependency management tool and should work in any IDE that supports Maven. If you do not have Maven installed, you can follow the guide found at https://www.baeldung.com/install-maven-on-windows-linux-mac to install it on your machine. It is available for all OSes out there. I highly encourage you to clone the code to your local machine to follow along with the book.
The project object model (pom.xml ) file contains the Payara Micro Maven plugin that you can use to run the code sample. Change to the project directory and issue the following command:
mvn package payara-micro:start
How Do You Reach Me?
Writing a book is a tedious task, and as such, despite best efforts, there may be errors that escape through quality checks. I take full responsibility for all of them.
Should you encounter any such errors, need help with anything in this book, or just want to hang out for coffee, please do not hesitate to reach out to me personally email@example.com .
Once again, thank you for picking up this book. I hope you write better code after reading it. Let’s get started.
Table of Contents
About the Author
is a Java EE developer with Pedantic Devs. He has been in software development for close to a decade. He started with PHP and now does Java EE full time. His goal on Udemy is to help you get productive with powerful, modern, intuitive, and easy-to-use Java EE APIs. He will provide you with the best of vanilla, pure, and awesome Java EE courses to help you master the skills needed to solve whatever development challenge you have at hand.
About the Technical Reviewer
Chád (“Shod”) Darby
is an author, instructor, and speaker in the Java development world. As a recognized authority on Java applications and architectures, he has presented technical sessions at software development conferences worldwide (in the United States, UK, India, Russia, and Australia). In his 15 years as a professional software architect, he’s had the opportunity to work for Blue Cross/Blue Shield, Merck, Boeing, Red Hat, and a handful of start-up companies.
Chád is a contributing author to several Java books, includingProfessional Java E-Commerce (Wrox Press),Beginning Java Networking (Wrox Press), andXML and Web Services Unleashed (Sams Publishing). Chád has Java certifications from Sun Microsystems and IBM. He holds a BS in computer science from Carnegie Mellon University. You can visit Chád’s blog at www.luv2code.com to view his free video tutorials on Java. You can also follow him on Twitter at@darbyluvs2code .