Spring Boot
Spring Boot
What is Spring?
There are many features, including in the Spring Framework, which is
also very popular. These features can be divided into twenty modules, which
allows for the resolution of many common problems in any Java application. Some
popular modules are explained below:
notably JPA, JDO, Hibernate, and iBatis. Spring provides integration classes for
in accordance with the configuration principles of Spring and integrates easily with the
object-oriented programming (OOP) by offering another way of thinking about the structure of the program.
. Spring Test
In other words, Spring Boot is an extension of the Spring framework, which aside from the
standard requirements for the configuration of a Spring application.
He adopts a Spring vision and has a faster and more efficient development ecosystem.
effective.
the application
. Automatic configuration
Inversion of control: the control over the object is reversed, the programmer is no longer the one who ...
control the object but the IOC container, so the classes do not handle instantiation
of other classes.
The implementation of the dependency injection proposed by Spring can be done in two ways
ways:
the best way to inject Beans: The recommended approach is to use the
constructor arguments for mandatory dependencies and setters for the
optional dependencies. Constructor injection allows for injecting values into
immutable fields (Which do not change) and facilitate testing.
BeanFactory VS ApplicationContext
BeanFactory is an interface representing a container that provides and manages instances of the
Bean. The default implementation instantiates the Beans when getBean() is called.
ApplicationContext is an interface representing a container that holds all the
information, metadata, and Beans in the application. The default implementation
Instantiate the Beans eagerly at application startup
Spring Bean
Spring beans are Java objects that are initialized by the Spring IoC container.
The scope of the default Bean in the Spring Framework
Spring Security
Spring Security is a separate module of the Spring framework that focuses on providing
of authentication and authorization methods in Java applications. It takes
also addresses most common security vulnerabilities, such as the
CSRF attacks.
To use Spring Security in web applications, you can start with a
simple annotation: @EnableWebSecurity .
Name some design patterns used in the context of Spring?
Let's take a look at the specific use cases of the last three:
● @Controller indicates that the class plays the role of a controller and detects
● @Service indicates that the class contains the business logic and calls the methods
● @Repository indicates that the class defines a data repository; its work
@Autowired
This annotation is applied to fields, setter methods, and
Constructors. The @Autowired annotation implicitly injects the object dependency.
When you use @Autowired on fields and pass the values of
fields with the help of the property name, Spring automatically assigns the fields to
transmitted values.
Configuration
This annotation is used on classes that define beans. @configuration is
an analog configuration XML file - it is a configuration using the class
Java. The Java class annotated with @Configuration is a configuration in itself and
will have methods to instantiate and configure the dependencies.
@bean
This annotation is used at the method level. The @Bean annotation works
with @Configuration to create Spring beans. As mentioned
previously, @ Configuration will have methods to instantiate and configure the
dependencies. These methods will be annotated with @Bean. The method annotated with
this annotation works as a bean ID and creates and returns the actual bean.
@lazy
This annotation is used on component classes. By default, all the
auto-generated dependencies are created and configured at startup. But if you want
to initialize a bean lazily, you can use the @Lazy annotation
class. This means that the bean will be created and initialized only when it is requested.
the first time. You can also use this annotation on classes
de@configuration. This indicates that all
The methods@ Beandans@ Configuration must be lazily initialized.
@ Component
This annotation is used on classes to indicate a component
Spring. The @Component annotation marks the Java class as a bean or said
component so that the Spring component analysis mechanism can be added
in the context of the application.