Spring Framework

  • Uploaded by: chiradip_mandal
  • 0
  • 0
  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Spring Framework as PDF for free.

More details

  • Words: 870
  • Pages: 27
Welcome to the Spring Session Chiradip

Lean Software Development Practice Series

J2EE (Now JEE) Frameworks • What? • Why? • How? (intention) • With what? (composition)

J2EE (Now JEE) Frameworks ✤ Sun J2EE (now JEE) ✤ EJB ✤ JSP-Servlet-JSF

✤ Third party frameworks ✤ Struts ✤ Hibernate

What is Spring Framework? • One-stop shop for enterprise application development

• Spring is modular - you can pick one or a combination

• Non-intrusive application

development & management framework

Lets write our first Spring App...

✤ See it on my iWeb Spring page and eclipse

IoC Fundamentals

• What is IoC? • Dependency Injection • “Plugin pattern” - special mention

IoC Fundamentals

✤ Different types of DI ✴ Constructor injection ✴ Setter Injection ✴ Interface Injection

(contd...)

AOP Fundamentals ✤ Aspect orientation is a different paradigm ✤ Special abstraction over object orientation ✤ Example - Fruit is a class and mango,

pineapple, apple etc are objects and this situation perfectly fits in the objectoriented space.

AOP Fundamentals

(contd...)

✤ Now think of Pest Management!! ✤ What about harvesting then?

AOP Fundamentals

(contd...)

A problem that applies to parts of the object model that are not conveniently related, or that are not related in an object-oriented manner. For example, a problem that applies to method return values in general, rather than to the methods for class, matching theanparts of the objectproblem model that the ofAarule single is not object-oriented as such. functionality will be applied to. This is analogous to the rule defining when a database trigger would apply. A package of functionality providing the cross-cutting requirements. A set of triggers for auditing database access would be analogous to an AOP aspect for auditing.

✤ Cross-cutting concern ✤ Point-cut ✤ Aspect ✤ Advice

The implementation of functionality that will be applied. This is analogous to the implementation of a database trigger.

Lets write our first Spring-AOP App...

See it on my iWeb Spring page and eclipse

Spring AOP ProxyFactoryBean ProxyFactoryBean One of the most important benefits of using a ProxyFactoryBean or another IoC-aware class to create AOP proxies, is that it means that advices and pointcuts can also be managed by IoC. This is a powerful feature, enabling certain approaches that are hard to achieve with other AOP frameworks. For example, an advice may itself reference application objects (besides the target, which should be available in any AOP framework), benefiting from all the pluggability provided by Dependency Injection.

Spring & ORM ✤ JDBC ✤ Java Persistence API (JPA) ✤ Java Data Objects (JDO) ✤ Hibernate ✤ Common Client Interface (CCI) ✤ iBATIS SQL Maps ✤ Oracle TopLink

Spring & ORM

✤ DAO

Spring & ORM

✤ Helper Classes

Spring MVC

• What is MVC? • How Spring supports it?

Spring MVC

• Model

(contd.)

Request

Response

Controller

View

• View • Controller

Model

Spring MVC

(contd.)

✤ Components ✤ Dispatcher - the entry point of the Spring

MVC is a servlet org.springframework.web.servlet.Dispatch erServlet

<servlet><servlet-name>timetracker <servlet-class> org.springframework.web.servlet.DispatcherServlet <param-name>contextConfigLocation <param-value>classpath:timetracker-servlet.xml

Spring MVC

(contd.)

timetracker-servlet.xml <servlet-mapping> <servlet-name>timetracker /

Spring MVC

(contd.)

Mappings

✤ The mapping converts all the incoming

urls into invocations of appropriate controller

✤DispatcherServlet loads the

HandlerMapping by autowiring

Spring MVC

(contd.)

✤ Mappings ...... for most purposes SimpleHandlerMapping (spring) is appropriate <property name="mappings"> <map> <entry key="/login" value-ref="loginHandler"/> <entry key="/accessDenied" value-ref="accessDeniedHandler"/> <entry key="/admin" value-ref="adminUserListController"/> <entry key="/admin/list" value-ref="adminUserListController"/> <entry key="/admin/view/**" value-ref="adminUserViewController"/> <property name="defaultHandler" ref="defaultHandler"/>

Spring MVC

(contd.)

✤ Controller ✤ controller is the core of the presentation logic for Spring MVC.

Once DispatcherServlet gets the GET request it chooses one suitable controller from the Mapping.

✤ A sample controller can be like the follows: It is used for single page rendering so very simple in nature

<property name="viewName" value="home"/>

Spring MVC

(contd.)

✤ Controller ✤

We have SimpleFromController as well. It can be overridden to do the following things:

• Provide reference data to the view for rendering. • Validate incoming request parameters. • Assign (and type-convert) incoming request parameters to attributes of a command object representing the form to be rendered. (This is known as binding the request parameters to the command object.) • Bind incoming form submissions to the command object. • Validate the command object upon form submission. • Forward to the original view if validation of the command object fails. • Populate the request with error objects representing the points of failure in validation. • Provide localized messages associated with the validation errors.

Spring MVC

(contd.)

✤ Views & Resolvers ✤

Normally in Spring MVC context we use JSP for the view, and we use it in a plug-able way.



The mechanism used to identify the rendering mechanism is resolver (view resolver).



UrlBasedViewResolver is a sample and usable class provided by Spring and can be used when all the views are processed by the same mechanism. <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

Spring MVC

✤ Validation (form) ✤ Exception Handling

(contd.)

Spring MVC ✤ Spring Web Flow <start-state idref="createUser"/> <end-state id="listUsers" view="externalRedirect:/admin"/>

(contd.)

Case study: Order Management Systems

Related Documents

Spring Framework
June 2020 17
Spring Framework
November 2019 27
Spring Framework
December 2019 60
Spring Framework
July 2020 11
The Spring Framework
October 2019 13