This is an Introduction to Spring Framework and Spring’s core concepts. In this tutorial, we will cover the main advantages, and features of Spring Framework. In the subsequent tutorials we will learn more about Spring and Spring Boot.
We know, Spring Framework is the most popular Application Frameworks in the world of Java developers. Spring is well known for providing abstractions and an infrastructural framework for almost everything that can be done by Java. On high level, if you want to use java for Accessing a Database or a NoSql DataStore, create a Web Application, interact with a RESTful service (etc. etc.) Spring already has got frameworks or abstractions for it.
1.1 Spring Projects
You must understand Spring Architecture to know more about various modules. Spring has so many modules and projects. Many of them will not even be needed for learning the Spring Framework. Below are some of the major Spring Projects which you will most likely be using when you write an enterprise application using Spring.
- Spring Core: The base of Spring. It includes Spring DI and IOC, which is also called as Dependency Injection (DI) and Inversion of Control (IOC).
- Spring MVC: An abstraction of JSP/Servlet for building Web Based Applications.
- Spring AOP: Quick components for writing Aspects and Aspect Oriented Programming.
- Spring Data: A set of frameworks to provide uniform way of accessing data across different types of Datastores.
- Spring REST: Spring components to write RESTful web services.
- Spring Data JPA: A framework under Spring-data that enhances the Java Persistence API implementations.
- Spring Security: An authentication and authorisation framework for web based applications.
- Spring Integration: A Framework for streamed data processing that adheres to Pipes and Channels Integration Pattern.
1.2 How to Learn Spring ?
In the reality, Spring Framework is very big and can’t be learnt in a tutorial or two. The best way to learn Spring is to start with the Spring-Core, understand Dependency Injection & Inversion of Control, Learn what is Bean Factory and Bean Lifecycle, try plenty of Hello World programs.
It is really important to understand and try above things as these are the base of almost everything in Spring Framework. Once you are familiar with the base components and principles of Spring all the other modules are really easy to pick.
2 Features of Spring
Although, Spring has proven its usefulness in many of aspects of developing industry level softwares, we will go over some of the key benefits of Spring Framework.
Prior to Spring, the enterprise applications use to be based around Enterprise Java Beans (EJB). EJB is famous for its complexity, bulkiness and longer development times. In contract Spring Frameworks is merely based on Plain Old Java Objects (POJO) and plain java classes.
Although, Spring has vast and has large number of tools, you don’t need to use all of it. The Spring Developers smartly made it modular. In simpler words, it means different tools or components in Spring are provided as independent Java archives. If you want to use Spring APO and you need only spring AOP archive (along with couple of core libraries).
Any Spring application has an inbuilt container, which is responsible for providing a context in an application. The container creates and manages the instances of classes inside the Springs Context. The Container also takes care of the object to object dependencies, called as dependency injection. Having a container and context based mechanism, Spring applications are often really easy to Unit Test as well as Integration Test. You just need to provide a ‘test’ context and the entire application will be easy for testing.
2.4 Bean Factory
Spring Bean Factory is backed by Spring Container. The classes which are declared as Spring Beans are instantiated by Spring Bean Factory. We don’t need to use the
new keyword anymore. The Bean factory can instantiate Beans lazily or eagerly (based on the specified policy). The beans are created in an Application context and their life span is with a config called as Bean Scopes. While doing so, if the bean has dependency over other beans they will be instantiated and injected as well. This mechanism as calls as Dependency Injection.
As mentioned earlier, Spring is the most popular Java Application Framework. There are certain benefits of using a popular framework. The popular frameworks are always well maintained, and well supported. Plenty of resources, learning materials and hacks are available over the internet. In an organisation or a wider community of Spring using the developer can speak a common language and terminology.
In this short tutorial we had an Introduction to Spring Framework. We learnt what the the major modules of Spring, and Spring features. We had a brief overview of spring modularity, popularity, spring container and spring Bean Factory. In the upcoming tutorials we will learn more about Spring Framework.