By AmarSivas | | Updated : 2018-10-18 | Viewed : 685 times
This tutorial introduces about what is Spring? What is the architecture of Spring frame work? What are the Spring features?
The Framework is Semi-finalized Software, which helps us to implement the Web/Enterprise application. The Developer can only concentrate on the business requirement. The Framework gives implemented code files for common functionalities such as Transaction Management, Security Management, and Data accessing layer, and soon. So, the Developer need not worry about these common functionalities. the code for common functionalities for the entire application has been reduced and handled by the Framework. So, the framework facility makes developer life easy.
When Spring introduced, the EJB is one of the option which is for developing the Web/Enterprise applications. EJB works with Container. So, EJB is heavy Wight. In EJB, the components coupled tightly. EJB is hard to use in the implementation of Web/Enterprise application. Unlike Spring, it supports only JPA Transaction Management only.
Spring Framework introduced for the replacement of EJB 2.0. EJB 2.0 has some drawbacks, which are some of them mentioned in the above. Spring comes with features so that the Developer can concentrate on business requirement. It removes redundant and boiler-plate code related to standard functionalities such as Transaction management, database connection, and so on. So, Developer can code for business requirement. Spring has very beneficiary features and modules to develop the application efficiently. It has defined with different types of sub-frameworks. The Developer can use any sub-framework or modules as per his requirement.
The main feature of Spring core is bean instantiation and initialization with the collaboration of other beans. Spring Framework has responsibility for creating a bean instance. After instantiation, Spring collaborates the beans as a dependency with the independent bean.
Spring framework is light weighted application framework and open source also. Rod Johnson has introduced the Spring framework in 2002. A frame work, a semi-finished software, provides entire infrastructure for building an application. Consisting of infrastructure like Spring framework is very useful for implementing an application in less time. Unlike other frame works, Spring can be used as needed as required. Suppose if you want to implement the application by using other framework like Struts, these type of frameworks forces us to use its framework API but, in case of Spring, Spring never ask about usage of framework API. We can use required modules and can be ignored remaining modules in Spring framework.
In large-scale application can be divided as different individual components. Hence Dependency Injection should be required in a large-scale application.
ApplicationContext represents the IoC Container. IoC Container instantiate, initialize and collaborate Spring beans as per Configuration defined in beans.xml. The Configuration file can be XML or annotations or Java code.
Spring framework is made up with different type of modules, which are useful for developing the applications. Please find the below given diagram for all the modules in the spring framework. Please find the below given diagram.
Tight coupling means that degree of components dependency is more. Here dependency between the components is more. However, it is less for Loosely coupled components. If the application has the tightly coupled components, then it is hard to modify the code.
The Inversion of Control is a mechanism which will be used by spring Container for bean instantiation. Spring takes responsibility for bean instantiation and initialization. Usually, Container recognizes and instantiates dependency bean first. After that, dependency will be injected into the dependent bean. However, in Spring, it executes reverse. That’s why, it named as Inversion of Control.
For a clean separation logic, Each specific functionality should be defined as separate Component in the large-scale application. Sometimes one bean needs to get injected into another bean. Spring creates the dependent bean with an injection of Dependency beans.
In OOP model, the classes/ objects have some relationships to make modularity. However, in AOP model, the program can be modularized.
In Spring, the IoC container instantiate the bean, but it cannot create on its own. Developer should provide the configuration/Meta data. There three types of configuration are available now. 1. XML Based Configuration 2. Annotation Based Configuration 3. Java Based Configuration
It allows the Spring to collaborate the dependency bean automatically. So, we no need to give dependency reference for dependency injection.
This is an abstract layer for Data Persistence layer. It helps to integrate Persistence API i.e., JDBC and Hibernate to save the data into the database. Spring removes boiler-plate code for database connection, transaction management, exception handling and soon. So, developer need not worry about all these problems. Developer can easily write the code for database transactions only.
This helps developer to handle transaction in a better way. Spring provided the declarative transaction management. So, without disturbing the existing code, transactions can be handled in a better way. In Spring, coding is not required for managing transaction management. So, Spring manages Transaction Management by using configuration.
This is a sub framework provided by Spring. Here all common code blocks for an web application is been provided. So, Developer can concentrate the only on functionality part.
Spring frame provide a wide range of option to test the entire application. We can use less set up for testing the application.
Spring Framework Architecture is designed with a number of modules. These modules are designed for specific functionality. So, all together defined as a framework.
Here all modules grouped as layers as Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation, Messaging, and Test. We will have a brief description of these modules.
The basic modules (Spring-core and spring-beans) contains Spring Container that is BeanFactory. The fundamental features of Spring, which are Spring Beans’ Life Cycle and Dependency Injection, will be handled by the Spring Container here.
Aspect-oriented Programming, in short AOP, allows us to implement cross-cutting concerns. cross-cutting concerns mean functionality that can be applied in different places of the application. The code for the same functionality will be scattered in the entire application. So handling of scattered and repeated code will be difficult for enhancing. AOP resolved this problem. AOP modularizes these cross-cutting concerns by separating these cross-cutting concerns. AOP allows modularized code can be invoked in anywhere application by configuration
It is an abstraction layer for JDBC programming. Here we can communicate with Database by configuring the ORM tools like Hibernate, Ibatis with these modules. It will also provide an integration layer for ORM and Spring framework.
A set of required features for the implementation of a web application will be given by these layers. MVC (Model, View, and Controller ) and REST web services are main features form this layer.