Spring Boot PP

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

SPRING BOOT

Manoj D K
Emp id :- 2205835
Dependency Injection

Dependency Injection is a form of Inversion of Control .

Also known as the Hollywood principle ,

" Don't call us , we'll call you ! "

MyService is given instances of ItemDAO and LabelDAO . MyService isn't


responsible for looking up DAOS .
Benefits of Dependency Injection

• Ensures configuration and usages of services are separate.

• Can switch implementations by simply changing the configuration.

• Enhances testability as mock dependencies can be injected

• Dependencies are easily identified

 No need to read the source code to see what dependencies your code talk to.
Dependency Injection in Spring

There are multiple ways of setting up dependency configuration in spring.


• XML

• Annotation

• JavaConfig

• …..

It is possible to mix and match definition styles.


XML
Annotation
JavaConfig
Spring Core

So what is Spring?
• IoC container
• Lightweight framework
• Fully modularized (High decoupling)
• Considered an alternative / replacement for the Enterprise
JavaBean(EJB) model
• Flexible
a) Programmer decide hoe to program
What Spring Offers?
• Dependency Injection (DI)
DI implemented through IoC (inversion of Control)
• Aspect Oriented Programming
Runtime Injection based
• Portable Service abstractions
• Easily testable

What is bean?
• A bean is a class that has only state but no behavior
• A bean must contain a no – argument constructor.
• A bean should be serialized.
AOP in Spring
• AOP stands for Aspect Oriented Programming
• AOP is one of the key components of the Spring framework
• Paradigm for separating cross-cutting concerns in well-defined
software entities called “aspects”.
• Does not replace OOP.
• Complements OOP by modularizing crosscutting concerns.
• Still a matter of writing classes w/ fields & methods
• Complements OO programming
• Core business concerns vs. Crosscutting enterprise concerns
• Components of AOP
 Aspect – unit of modularity for crosscutting concerns
 Join point – well-defined points in the program flow
 Pointcut – join point queries where advice executes
 Advice – the block of code that runs based on the pointcut definition
 Weaving – can be done at runtime or compile time. Inserts the advice
(crosscutting concerns) into the code (core concerns).
• Aspects can be used as an alternative to existing technologies
such as EJB. Ex: declarative transaction management,
declarative security, profiling, logging, etc.
• Aspects can be added or removed as needed without changing
your code.
Consistent Abstract Classes for DAO Support
• Extend your DAO classes with the proper xxxDAOSupport class that matches your
persistence mechanism.
• JdbcDaoSupport
• Super class for JDBC data access objects.
• Requires a DataSource to be set, providing a JdbcTemplate based on it to subclasses.
• HibernateDaoSupport
• Super class for Hibernate data access objects.
• Requires a SessionFactory to be set, providing a HibernateTemplate based on it to subclasses.
• JdoDaoSupport
• Super class for JDO data access objects.
• Requires a PersistenceManagerFactory to be set, providing a JdoTemplate based on it to
subclasses.
• SqlMapDaoSupport
• Supper class for iBATIS SqlMap data access object.
• Requires a DataSource to be set, providing a SqlMapTemplate
Spring DAO Templates
• Built in code templates that support JDBC, Hibernate, JDO, and iBatis SQL
Maps
• Simplifies data access coding by reducing redundant code and helps avoid
common errors.
• Alleviates opening and closing connections in your DAO code.
• No more ThreadLocal or passing Connection/Session objects.
• Transaction management is handled by a wired bean
• You are dropped into the template with the resources you need for data
access – Session, PreparedStatement, etc.
• Code only needs to be implemented in callback methods.
• doInXXX(Object)
• Optional separate JDBC framework
Spring ApplicationContext
• A Spring ApplicationContext allows you to get access to the
objects that are configured in a BeanFactory in a framework
manner.
• ApplicationContext extends BeanFactory
• Adds services such as international messaging capabilities.
• Add the ability to load file resources in a generic fashion.
• Several ways to configure a context:
• XMLWebApplicationContext – Configuration for a web application.
• ClassPathXMLApplicationContext – standalone XML application context
• FileSystemXmlApplicationContext
• Allows you to avoid writing Service Locators
What is Spring MVC
Modules of Spring Framework on the Web layer:
• Web module provides basic web-oriented integration features and the initialization of
the loC container using servlet listeners and a web application context.
• Servlet module contains Spring MVC implementation for web applications.
• A web framework built on the Servlet API.
• Provides Model-View-Controller (MVC) architecture and ready components that can
be used to develop flexible and loosely coupled web applications.
• Request-driven, designed around a central Servlet that dispatches requests to
controllers - the DispatcherServlet.
MVC (Model-view-Controller)

An architectural pattern commonly used for developing user interfaces.


An application is divided into 3 interconnected parts:
a) Model - Responsible for managing data of the application.
b) View - Responsible for displaying the model data to user.
c) Controller - Responsible for processing user requests and building an
appropriate model and passes it to the view for rendering.
DispatcherServlet
• Spring MVC is designed around a central servlet named DispatcherServlet.
• DispatcherServlet acts as a central entry point to the Spring MVC application.
• Every request is handled by DispatcherServlet .
• DispatcherServlet is an expression of the Front Controller pattern.

Controllers
• The Front Controller's job is to determine a suitable handler capable of performing
the actual processing.
• Handlers are Spring MVC Controllers.
• The selected Controller interacts with the service layer; the relevant data are collected
in a model.
• When the Controller has finished processing, the Front Contróller determines which
view to render.
View
• When the Controller has finished processing, the Front Controller determines
which view to render.
• The Front Controller passes the model to the view which is finally which is
finally rendered on the browser.

Important annotation
Some important annotations which are used in a Spring MVC application.
 @Controller and @RestController
 @RequestMapping
@GetMapping, @PostMapping, @PutMapping and @DeleteMapping.
 @RequestParam, @PathVariable
 @RequestBody
 @ResponseBody
Thank you

You might also like