Spring is a framework, which provides a bunch of classes, by using this we don’t need to write boilerplate logic in our code, so Spring provides an abstract layer on J2ee.
For Example in Simple JDBC, the Application programmer is responsible for
- Loading the driver class
- Creating the connection
- Creating a statement object
- Handling the exceptions
- Creating query
- Executing query
- Closing the connection
Which is treated as boilerplate code as every programmer write the same code. So for simplicity, the framework takes care of boilerplate logic and the programmer has to write only business logic.
So by using the Spring framework, we can develop projects rapidly with minimum lines of code, without any bug, the development cost and time also
So Why to choose Spring as struts are there
Struts is a framework which provides the solution to web aspects only and struts is invasive in nature. Spring has many features over struts so we have to choose Spring.
- Spring is Noninvasive in nature: That means you don’t need to extend any classes or implement any interfaces to your class.
- Spring is versatile: That means it can be integrated with any existing technology in your project.
- Spring provides end to end project development: That means we can develop all the modules like the business layer, persistence layer.
- Spring is light weight: That means if you want to work on a particular module then, you don’t need to learn complete spring, only learn that particular module(eg. Spring JDBC, Spring DAO)
- Spring supports dependency injection.
- Spring supports multiple project development eg: Core java Application, Web Application, Distributed Application, Enterprise Application.
- Spring supports Aspect-oriented Programming for cross-cutting concerns.
So finally we can say Spring is an alternative to Struts. But Spring is not a replacement of J2EE API, As Spring supplied classes internally uses J2EE API classes. Spring is a vast framework so it has divided into several modules. No module is dependent to another except Spring Core. Some Important modules are
- Spring Core
- Spring JDBC
- Spring AOP
- Spring Transaction
- Spring ORM
- Spring MVC