Skip to content

Latest commit

 

History

History
92 lines (54 loc) · 3.84 KB

File metadata and controls

92 lines (54 loc) · 3.84 KB

Вопросы для собеседования

Spring Framework

Что такое Spring Framework?

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

к оглавлению

What Is Dependency Injection?

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.

к оглавлению

How Can We Inject Beans in Spring?

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.

Which Is the Best Way of Injecting Beans and Why?

к оглавлению

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.

What Is a Spring Bean?

The Spring Beans are Java Objects that are initialized by the Spring IoC container.

к оглавлению

What Is the Default Bean Scope in Spring Framework?

By default, a Spring Bean is initialized as a singleton.

к оглавлению

How to Define the Scope of a Bean?

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

к оглавлению

What Does the Spring Bean Life Cycle Look Like?

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 img.png

к оглавлению

Can We Have Multiple Spring Configuration Files in One Project?

Yes, in large projects, having multiple Spring configurations is recommended to increase maintainability and modularity.

к оглавлению

What Is Spring Boot?

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.

к оглавлению