Spring is a dependency injection container, with some very handy utility layers: web frameworks, security frameworks, testing frameworks, as well as component container that I will be delving into further in this blog.
So spring itself is quite an amazing tool, however, you may need some experience to know how to set it all up, or in some situations configurations can be quite slow. This is where spring boot comes in, this is an opinionated framework that greatly simplifies the configuration of applications, even with the ability to create production grade spring applications with zero-config.
With spring boot, production grade features such as health metrics, and an overall convention-over-configuration approach that can bring a huge boost into productivity for Kotlin and Java developers.
Spring also comes with concepts that make it easier for developers to follow the S.O.L.I.D principles. Thus encouraging cleaner code, and enables for techniques such as Test Driven Development to not only be possible, but a pleasant experience for collaborate development. One major principle: Single Responsibility Principle, can be made more feasible through the Inversion of Control (IoC) pattern that spring has a great implementation for.
Inversion of Control (IoC) through beans.
Inversion of control definition: a process in which an object defines its dependencies without creating them.
- This object delegates the job of constructing dependencies with the use of an IoC container.
Any object within an application that is managed by the Bean Factory ( The spring IoC container) within Spring are called beans.
Imagine an application with hundreds of classes, sometimes we want those instantiations to only be singletons, or other objects, and often we want to share those instantiations to other areas of the project. Eventually, this becomes way too complex, and this is where Inversion of Control is helpful. With the bean factory, we are able to provide containers with all the necessary metadata, and additional interfaces, and methods to use our methods.
These beans, come with so many utility perks, instantiations can be globally accessible within application by querying the bean factory, classes are simply annotated for their design pattern, and the beans implement the necessary methods, saving lots of development time. Testing becomes a breeze, with built in dependency injection helpers, subclasses of objects can be automatically mocked, without requiring any additional development work.
Architecture
The most common architecture within Spring is the n-tier architecture system, a set of horizontal layers:
This layers of isolation concept, ensures that one layer of the system should not impact another layer. Each layer should have very little knowledge about the inner workings of other layers, thus a guaranteed separation of concerns, and fairly simple to learn.
Beans are also used to enforce the communication of layers, and self describes the nature of the class. I.e, Service, Repository, Controller, etc.