Professional Documents
Culture Documents
Spring Boot PP
Spring Boot PP
Spring Boot PP
Manoj D K
Emp id :- 2205835
Dependency Injection
No need to read the source code to see what dependencies your code talk to.
Dependency Injection in Spring
• Annotation
• JavaConfig
• …..
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)
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