Annotation-based DI

From the beginning, the most common way of defining configuration in Spring has been XML-based. But when the complexity grew and navigation of beans became exhausted in the jungle of angle brackets, there was a demand for a second option to define configuration. As a result, Spring started support for annotation.

Annotation-based configuration is an alternate of XML-based configuration, and irelies on bytecode metadata. Spring started support for annotation with version 2.5. With annotation, the configuration moves from an XML to component class. Annotation can be declared on classes, methods, or at field level.

Let's understand the process of defining configuration through annotation. We will first understand this process ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.