In this article, we are going to talk about Spring In java and its types and features in an easy manner for beginners. Spring is one of the most popular Frameworks in java. Let’s get into the Article.
An open-source framework called Spring was developed to handle the complexities of developing enterprise applications. The Spring framework's layered design is one of its main benefits because it offers a cohesion foundation for J2EE application development while also allowing you to choose which of its components you utilize.
When it comes to size and transparency, spring is thin. The spring framework's basic version is about 1MB in size. Additionally, the processing overhead is really minimal.
Aspect-oriented programming is supported by Spring.
The programming approach known as "aspect-oriented programming" separates the business logic of the primary application from any auxiliary or supporting operations. AOP is a promising approach for object-oriented programming that makes it easier to separate cross-cutting concerns. This increases the modularity of the application and makes maintenance much simpler.
Application objects' life cycles and configuration are handled by Spring.
Using the fundamental Spring technology as a foundation, Spring includes an MVC web application framework. This framework supports several display technologies such as JSP, Velocity, Tiles, iText, and POI and is extensively configurable via strategy interfaces. But Spring MVC Framework can easily be replaced with different frameworks.
A general abstraction layer for transaction management is provided by the Spring framework. This makes it simple to demarcate transactions without having to deal with low-level concerns and enables the developer to add the pluggable transaction managers. The transaction capability provided by Spring can be used in contexts without containers and is not restricted to J2EE environments.
The AOP framework is one of Spring's essential elements. Spring is when AOP is used:
1. To offer declarative business services, particularly to replace EJB declarative services Declarative transaction management, which expands on Spring's transaction abstraction, is the most significant example of such a service.
2. To enable users to incorporate unique features, enhancing their OOP usage with AOP
Database access is related to the ORM package. Well-known object-relational mapping APIs like JDO, Hibernate, and iBatis, offer integration layers.
The web application development stack for Spring, which also contains Spring MVC, includes the Spring Web module.
The main purpose of Spring's DAO (Data Access Object) support is to standardize the data access work that uses JDBC, Hibernate, or JDO.
By adding support for message sources, the Observer design pattern, and the capability for application objects to access resources using a unified API, this package expands upon the beans package.
The MVC implementations for web applications are provided by this module.
The most crucial part of the Spring Framework is the Core package.
The characteristics of Dependency Injection are provided by this component. The Bean Factory offers a factory architecture that isolates your actual program logic from dependencies like object initialization, creation, and access.
1. Before to Advice: it runs prior to a join point.
2. After Returning Advice: it starts running once a join point has finished without throwing an exception.
3. After Throwing Advice: it is called if the function throws an exception before exiting.
4. Regardless of the result, it executes after a join point.
5. Around Advice: It runs both prior to and following a connecting point.
The fundamental idea behind the dependency injection pattern commonly referred to as the Inversion of Control pattern, is that instead of creating your objects, you should specify how they should be produced. You indicate which services are required by which components in a configuration file rather than explicitly connecting your components and services together in code. Then, the task of connecting everything is carried out by a container (in the case of the Spring framework, the IOC container).
Applying IoC means that each object in the system is coordinated by an external entity, which provides objects with their dependencies at the moment of creation. Dependencies are therefore introduced within objects. IoC stands for "inversion of responsibility," and it refers to how an item receives references to cooperating objects.
Lets we have two classes-Car and an Engine. The car has an object Engine.
An object can be instantiated in a variety of ways. Using a new operator is an easy and typical method.
In this case, the Car class has an object for the engine, which we instantiated using the new operator.
These days, we delegate instantiation to a third party and give them the task of doing so. In order for the car to function, the engine's object must be provided by a third party. The chosen third party chooses the type to use and the instantiation time for the instance. A third party injects the class Car and class Engine dependencies. This agreement as a whole also includes configuration information. The name of the entire procedure is dependency injection.
A class called an Aspect implements issues that span many classes, such as logging. Just a name, really.
This is a stage in a program's execution, such as when a method is carried out. A join point describes a method execution in Spring AOP at all times.
At the specific join point, an aspect took the action. As an illustration, add logging before the getting employee name() method is executed. We are using the before guidance in this instance.
A pointcut is an expression that chooses how advice will be executed at the matched joint point. AspectJ pointcut expression language is what Spring uses by default.
Weaving is the process of constructing proxy objects from the target object.
1. Assures that service configuration and usage are distinct.
2. The implementations can be changed by altering the settings.
3. Increases Testability by allowing the injection of mock dependencies.
4. It is simple to spot dependencies.
5. There's no need to read code to find out which dependencies your function communicates with.
After executing a no-argument function Object() { [native code] } or no-argument static factory function to instantiate your bean, you may implement setter-based DI by calling the setter methods on your beans.
A function Object() { [native code] } is invoked with a number of parameters, each of which represents a collaborator, to accomplish constructor-based DI.
When using interface-based dependency injection, we create an interface and receive the instance when we implement it.