Smart Dependency Injection With Spring: Assignability (Part 2 of 3)

Preface

The Spring Framework  is a very powerful framework and provides first class support for dependency injection (DI). This article is the second one in my series dedicated to dependency injection  with Spring Framework. My series is split into these three articles:

In This Article, You Will Learn:

  • How to inject beans by a common interface
  • How to inject beans by ancestor (usually abstract) class
  • How to inject beans by annotation

Overview

In my previous article, I reviewed the DI basics: different configuration types, injection variants, injection rules, or injected types. Most of it is well known and that article serves just as a summary.

Data Integrity in NoSQL and Java Applications Using Bean Validation

The NoSQL databases are famous because they are schemaless. That means a developer does need to care about a pre-defined type as it does on a relational database; thus, it makes it easier for developers to create an application. However, it has a considerable price once there is no structure that is not trivial to validate it on the database. To ensure integrity, the solution should work on the server side. There is a specification and framework in the Java world that is smoother and annotation-driven: bean validation. This post will cover how to integrate bean validation in a NoSQL database.

Bean Validation, JSR 380, is a specification which ensures that the properties of a Class match specific criteria, using annotations such as @NotNull, @Min, and @Max, also create its annotation and validation. It is worth noting bean validation does not, necessarily, mean an anemic model; in other words, a developer can use it with good practices to get data integrity.