- Что такое Spring Framework?
- What Is Dependency Injection?
- How Can We Inject Beans in Spring?
- Which Is the Best Way of Injecting Beans and Why?
- What Is a Spring Bean?
- What Is the Default Bean Scope in Spring Framework?
- How to Define the Scope of a Bean?
- What Does the Spring Bean Life Cycle Look Like?
- Can We Have Multiple Spring Configuration Files in One Project?
- What Is Spring Boot?
Spring is the most broadly used framework for the development of Java Enterprise Edition applications. Further, the core features of Spring can be used in developing any Java application.
We use its extensions for building various web applications on top of the Jakarta EE platform. We can also just use its dependency injection provisions in simple standalone applications
Dependency injection, an aspect of Inversion of Control (IoC), is a general concept stating that we do not create our objects manually but instead describe how they should be created. Then an IoC container will instantiate required classes if needed.
A few different options exist in order to inject Spring beans:
- Setter injection
- Constructor injection
- Field injection
The configuration can be done using XML files or annotations.
The recommended approach is to use constructor arguments for mandatory dependencies and setters for optional ones. This is because constructor injection allows injecting values to immutable fields and makes testing easier.
The Spring Beans are Java Objects that are initialized by the Spring IoC container.
By default, a Spring Bean is initialized as a singleton.
In order to set Spring Bean's scope, we can use @Scope annotation or “scope” attribute in XML configuration files. Note that there are five supported scopes:
- Singleton
- Prototype
- Request
- Session
- Global-session
First, a Spring bean needs to be instantiated based on Java or XML bean definition. It may also be required to perform some initialization to get it into a usable state. After that, when the bean is no longer required, it will be removed from the IoC container.
The whole cycle with all initialization methods is shown in the image

Yes, in large projects, having multiple Spring configurations is recommended to increase maintainability and modularity.
Spring Boot is a project that provides a pre-configured set of frameworks to reduce boilerplate configuration. This way, we can have a Spring application up and running with the smallest amount of code.