0% found this document useful (0 votes)
20 views5 pages

Spring Boot

The document describes the Spring Framework, including its popular features such as Spring JDBC, Spring MVC, Spring ORM, Spring AOP, and Spring JMS. It also explains Spring Boot and some Spring annotations like @Autowired, @Configuration, @Bean, and @Component.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Spring Boot

The document describes the Spring Framework, including its popular features such as Spring JDBC, Spring MVC, Spring ORM, Spring AOP, and Spring JMS. It also explains Spring Boot and some Spring annotations like @Autowired, @Configuration, @Bean, and @Component.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The Spring Framework is one of the most popular frameworks for development.

Java applications. It is very useful for dependency injection (DI - Dependency)


Injection) or inversion of control (IOC - Inversion Of Control), which helps to develop
weak coupling applications, which automatically helps to properly test any
Java application.

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:

. Spring JDBC: Every time we want to extract data from a database

RDBMS data, we can use Spring's default JDBC structure.

. Spring MVC: Primarily used for developing a Web application.

. Spring ORM: It is a module covering many persistence technologies.

notably JPA, JDO, Hibernate, and iBatis. Spring provides integration classes for

each of these technologies, so that each technology can be used

in accordance with the configuration principles of Spring and integrates easily with the

Spring transaction management.

. Spring AOP: Aspect-Oriented Programming (AOP) complements programming

object-oriented programming (OOP) by offering another way of thinking about the structure of the program.

. Spring JMS: JMS (Java Message Service) is a middleware used to send

messages between clients by sending messages to a message queue,

which are then used whenever possible to execute a transaction.

. Spring Test

. Spring Expression Language (SPEL)

What is Spring Boot?


Spring Boot is actually based on all the default features of Spring. Core Spring
and MVC can handle complete functions of any Java application. According to the
complexity and configuration, spring boot can help us a lot to reduce complexity
related to the spring configuration.

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.

Here are some of the features of Spring Boot:

. Starter-type dependencies to simplify the construction and configuration of

the application

. Integrated server to avoid complexity when deploying applications

. Metrics, verification, and outsourced configuration

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

Dependency injection: injecting one bean into another to find automatically

the components we need at runtime.

The implementation of the dependency injection proposed by Spring can be done in two ways
ways:

Injection by the constructor


Injection by unsetter

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

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


The scope of a Bean
To define the scope of a Spring Bean, we can use the @Scope annotation or the attribute
"scope" in XML configuration files. There are five supported scopes:
Singleton
Prototype
Request
Session
Global session
the Java-based configuration of Spring
It is one of the ways to configure Spring-based applications in a way
secure. It is an alternative to the XML-based configuration.
Can we have multiple Spring configuration files in a project?
Yes, in large projects, several spring configurations are recommended for
increase maintainability and modularity.
You can load multiple Java configuration files:
1 Configuration
2 @Import({[Link], [Link]})
3 public class AppConfig {
Where to upload an XML file that will contain all the other configurations:
1 ApplicationContext context = new ClassPathXmlApplicationContext("[Link]");
And inside this XML file, you will have:
1 <import resource="[Link]"/>
2 <import resource="[Link]"/>

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?

● Singleton Pattern: Beans on a Singleton Scale

● Factory model: factory classes of beans

● Prototype pattern: Prototype-scale beans

● Adapter Model: Spring Web and Spring MVC

● Proxy model: support for aspect-oriented programming spring

● Model of model of model: JdbcTemplate, HibernateTemplate, etc.

● Front controller: Spring MVC DispatcherServlet

● Data access object: support for Spring DAO

● Model View Controller: Spring MVC

Difference between @Controller, @Component, @Repository and @Service Annotations

According to the official Spring documentation, @Component is a generic stereotype for

Every component managed by Spring. @Repository, @Service and @Controller are

specializations of @Component for more specific use cases, for example,

in the persistence, service, and presentation layers, respectively.

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

the @RequestMapping annotations in the class

● @Service indicates that the class contains the business logic and calls the methods

in the repository layer

● @Repository indicates that the class defines a data repository; its work

involves intercepting platform-specific exceptions and rethrowing them

as one of the unified unchecked exceptions of Spring


The annotations of Spring

@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.

You might also like