Spring MVC 2017

Содержание

Слайд 3

INTRODUCING MVC AND SPRING MVC

INTRODUCING MVC AND SPRING MVC

Слайд 4

What is MVC?

Introducing MVC and Spring MVC
What is MVC?

What is MVC? Introducing MVC and Spring MVC What is MVC?

Слайд 5

Introduction to Web Spring MVC

Spring MVC provides a clear separation between a

Introduction to Web Spring MVC Spring MVC provides a clear separation between
model, view and controller
Provides both XML-based and annotation-based approaches.
Enriched by Spring application context.
Provides a broad range of pre-configured facilities.
Takes convention over configuration approach.
Uses open-close principle.

Main features

Benefits

Decoupling views and models
Reduces the complexity of your design
Makes code more flexible
Makes code more maintainable

Слайд 6

What is MVC?

Introducing MVC and Spring MVC
Spring MVC WebApplicationContext Hierarchy

What is MVC? Introducing MVC and Spring MVC Spring MVC WebApplicationContext Hierarchy

Слайд 7

What is MVC?

Introducing MVC and Spring MVC
Spring MVC WebApplicationContext Hierarchy

What is MVC? Introducing MVC and Spring MVC Spring MVC WebApplicationContext Hierarchy

Слайд 8

Introducing MVC and Spring MVC
Spring MVC Request Life Cycle

Introducing MVC and Spring MVC Spring MVC Request Life Cycle

Слайд 9

Introducing MVC and Spring MVC
Intercepting requests with a HandlerInterceptor


Introducing MVC and Spring MVC Intercepting requests with a HandlerInterceptor

Слайд 10

Introducing MVC and Spring MVC
Spring MVC Request Life Cycle

BeanNameViewResolver
FreeMarkerViewResolver
InternalResourceViewResolver
JasperReportsViewResolver
ResourceBundleViewResolver
UrlBasedViewResolver
VelocityLayoutViewResolver
VelocityViewResolver
XmlViewResolver
XsltViewResolver

Introducing MVC and Spring MVC Spring MVC Request Life Cycle BeanNameViewResolver FreeMarkerViewResolver

Слайд 11

Introducing MVC and Spring MVC
Spring MVC Configuration

To configure Spring MVC support for

Introducing MVC and Spring MVC Spring MVC Configuration To configure Spring MVC
web applications:
Configuring the root WebApplicationContext
Configuring the servlet filters required by Spring MVC
Configuring the dispatcher servlets within the application

Слайд 12

DISPATCHERSERVLET, CONTROLLER, VIEW, MODEL

DISPATCHERSERVLET, CONTROLLER, VIEW, MODEL

Слайд 13

DispatcherServlet, Controller, View, Model
DispatcherServlet

DispatcherServlet, Controller, View, Model DispatcherServlet

Слайд 14

DispatcherServlet, Controller, View, Model
DispatcherServlet Code Overview

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
...

DispatcherServlet, Controller, View, Model DispatcherServlet Code Overview xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> ...

Слайд 15

DispatcherServlet, Controller, View, Model
DispatcherServlet Code Overview

DispatcherServlet, Controller, View, Model DispatcherServlet Code Overview

Слайд 16

DispatcherServlet, Controller, View, Model
DispatcherServlet Code Overview

DispatcherServlet, Controller, View, Model DispatcherServlet Code Overview

Слайд 17

DispatcherServlet, Controller, View, Model
DispatcherServlet Code Overview

DispatcherServlet, Controller, View, Model DispatcherServlet Code Overview

Слайд 18

DispatcherServlet, Controller, View, Model
DispatcherServlet Code Overview

DispatcherServlet, Controller, View, Model DispatcherServlet Code Overview

Слайд 19

DispatcherServlet, Controller, View, Model
Controllers

Controllers provide access to the application behavior that you

DispatcherServlet, Controller, View, Model Controllers Controllers provide access to the application behavior
typically define through a service interface.
Controllers interpret user input and transform it into a model that is represented to the user by the view.
Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers.

@RequestMapping("/contacts")
@Controller
public class ContactController {
private ContactService contactService;
@RequestMapping(method = RequestMethod.GET)
public String list(Model uiModel) {
List contacts = contactService.findAll();
uiModel.addAttribute("contacts", contacts);
return "contacts/list";
}
@Autowired
public void setContactService(ContactService contactService) {
this.contactService = contactService;
}
}

Слайд 20

DispatcherServlet, Controller, View, Model
View Examples

DispatcherServlet, Controller, View, Model View Examples

Слайд 21

DispatcherServlet, Controller, View, Model
Model examples

Map
Populated by controllers
Contains all data needed by

DispatcherServlet, Controller, View, Model Model examples Map Populated by controllers Contains all
the „view“
Not containing business logic

Слайд 22

DispatcherServlet, Controller, View, Model
Supported method return types

ModelAndView
Model
Map
View
String
void
….

DispatcherServlet, Controller, View, Model Supported method return types ModelAndView Model Map View String void ….

Слайд 23

INTERNATIONALIZATION(I18N) / THEMES / TEMPLATES (APACHE TILES)

INTERNATIONALIZATION(I18N) / THEMES / TEMPLATES (APACHE TILES)

Слайд 24

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Internationalization

Enable i18n in the early stage.

Internationalization(i18n) / Themes / Templates (Apache Tiles) Internationalization Enable i18n in the

Properties files within the e.g /WEB-INF/i18n folder:
The application*.properties
The message*.properties

Слайд 25

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Configuring i18n in DispatcherServlet

Internationalization(i18n) / Themes / Templates (Apache Tiles) Configuring i18n in DispatcherServlet

Слайд 26

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Configuring i18n in DispatcherServlet

Internationalization(i18n) / Themes / Templates (Apache Tiles) Configuring i18n in DispatcherServlet

Слайд 27

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Configuring i18n in DispatcherServlet

Internationalization(i18n) / Themes / Templates (Apache Tiles) Configuring i18n in DispatcherServlet

Слайд 28

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Example View

Internationalization(i18n) / Themes / Templates (Apache Tiles) Example View

Слайд 29

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Using Themes

Internationalization(i18n) / Themes / Templates (Apache Tiles) Using Themes

Слайд 30

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Using Themes

FixedThemeResolver
SessionThemeResolver
CookieThemeResolver

Internationalization(i18n) / Themes / Templates (Apache Tiles) Using Themes FixedThemeResolver SessionThemeResolver CookieThemeResolver

Слайд 31

Internationalization(i18n) / Themes / Templates (Apache Tiles)
Using templates

Internationalization(i18n) / Themes / Templates (Apache Tiles) Using templates

Слайд 32

MAPPING OF URLS, VALIDATION SUPPORT

MAPPING OF URLS, VALIDATION SUPPORT

Слайд 33

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views @RequestMapping

Слайд 34

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;

Слайд 35

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;
headers
headers="myHeader=myValue“;
 headers="!myHeader=myValue“;
 headers="myHeader", headers="!myHeader“;

Слайд 36

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;
headers
headers="myHeader=myValue“;
 headers="!myHeader=myValue“;
 headers="myHeader", headers="!myHeader“;
method
RequestMethod.GET, RequestMethod.POST etc.

Слайд 37

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;
headers
headers="myHeader=myValue“;
 headers="!myHeader=myValue“;
 headers="myHeader", headers="!myHeader“;
method
RequestMethod.GET, RequestMethod.POST etc.
name
params
params="myParam=myValue“;
 params="!myParam=myValue“;

Слайд 38

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;
headers
headers="myHeader=myValue“;
 headers="!myHeader=myValue“;
 headers="myHeader", headers="!myHeader“;
method
RequestMethod.GET, RequestMethod.POST etc.
name
params
params="myParam=myValue“;
params="!myParam=myValue“;
path

Слайд 39

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;
headers
headers="myHeader=myValue“;
 headers="!myHeader=myValue“;
 headers="myHeader", headers="!myHeader“;
method
RequestMethod.GET, RequestMethod.POST etc.
name
params
params="myParam=myValue“;
params="!myParam=myValue“;
path
produces

Слайд 40

Mapping of URLs, Validation support (JSR-349)
Mapping of URLs to the views

@RequestMapping

Mapping of URLs, Validation support (JSR-349) Mapping of URLs to the views

consumes
consumes="application/json“;
consumes=“!application/json“;
"text/plain", "application/*;
headers
headers="myHeader=myValue“;
 headers="!myHeader=myValue“;
 headers="myHeader", headers="!myHeader“;
method
RequestMethod.GET, RequestMethod.POST etc.
name
params
params="myParam=myValue“;
params="!myParam=myValue“;
path
produces
value

Слайд 41

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 42

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 43

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 44

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 45

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 46

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 47

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 48

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 49

Mapping of URLs, Validation support (JSR-349)
Mapping example

Mapping of URLs, Validation support (JSR-349) Mapping example

Слайд 50

Mapping of URLs, Validation support (JSR-349)
Mapping example

/spring-web/spring-web-3.0.5.jar

Mapping of URLs, Validation support (JSR-349) Mapping example /spring-web/spring-web-3.0.5.jar

Слайд 51

Spring MVC Annotations
Composed @RequestMapping Variants

@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping

@RequestMapping(method = RequestMethod.GET)
public Map get() {

Spring MVC Annotations Composed @RequestMapping Variants @GetMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping @RequestMapping(method

return …;
}

@GetMapping
public Map get() {
return …;
}

@RequestMapping(method = RequestMethod.POST)
public String add(@Valid AppointmentForm appointment, BindingResult result) {
return …;
}

@PostMapping
public String add(@Valid AppointmentForm appointment, BindingResult result) {
return …;
}

Слайд 52

Path Patterns

/myPath/*.do

Path Patterns /myPath/*.do

Слайд 53

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

Path Patterns /myPath/*.do /owners/*/pets/{petId}

Слайд 54

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/**

Слайд 55

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/**

Слайд 56

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/*

Слайд 57

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/*

Слайд 58

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

/hotels/{hotel}

/hotels/*

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/* /hotels/{hotel} /hotels/*

Слайд 59

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

/hotels/{hotel}

/hotels/*

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/* /hotels/{hotel} /hotels/*

Слайд 60

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

/hotels/{hotel}

/hotels/*

/**

/api/{a}/{b}/{c}

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/* /hotels/{hotel} /hotels/* /** /api/{a}/{b}/{c}

Слайд 61

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

/hotels/{hotel}

/hotels/*

/**

/api/{a}/{b}/{c}

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/* /hotels/{hotel} /hotels/* /** /api/{a}/{b}/{c}

Слайд 62

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

/hotels/{hotel}

/hotels/*

/**

/api/{a}/{b}/{c}

/public/**

/public/path3/{a}/{b}/{c}

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/* /hotels/{hotel} /hotels/* /** /api/{a}/{b}/{c} /public/** /public/path3/{a}/{b}/{c}

Слайд 63

Path Patterns

/myPath/*.do

/owners/*/pets/{petId}

/hotels/{hotel}/*

/hotels/{hotel}/**

/foo/bar*

/foo/*

/hotels/{hotel}

/hotels/*

/**

/api/{a}/{b}/{c}

/public/**

/public/path3/{a}/{b}/{c}

Path Patterns /myPath/*.do /owners/*/pets/{petId} /hotels/{hotel}/* /hotels/{hotel}/** /foo/bar* /foo/* /hotels/{hotel} /hotels/* /** /api/{a}/{b}/{c} /public/** /public/path3/{a}/{b}/{c}

Слайд 64

Spring MVC Annotations
@RequestBody

@PutMapping("/something")
public void handle(@RequestBody String body, Writer writer) throws IOException

Spring MVC Annotations @RequestBody @PutMapping("/something") public void handle(@RequestBody String body, Writer writer)
{
writer.write(body);
}

@PathVariable
@RequestParam
@RequestHeader
@RequestBody

Слайд 65

Spring MVC Annotations
@ResponseBody

@GetMapping("/something")
@ResponseBody
public String helloWorld() {
return "Hello World";
}

Spring MVC Annotations @ResponseBody @GetMapping("/something") @ResponseBody public String helloWorld() { return "Hello World"; } HttpMessageConverter

HttpMessageConverter

Слайд 66

Spring MVC Annotations
@RestController

@RestController

Spring MVC Annotations @RestController @RestController

Слайд 67

Spring MVC Annotations
@ModelAttribute on a method

// Add one attribute
// The return

Spring MVC Annotations @ModelAttribute on a method // Add one attribute //
value of the method is added to the model under the name "account"
// You can customize the name via @ModelAttribute("myAccount")
@ModelAttribute
public Account addAccount(@RequestParam String number) {
return accountManager.findAccount(number);
}
// Add multiple attributes
@ModelAttribute
public void populateModel(@RequestParam String number, Model model) {
model.addAttribute(accountManager.findAccount(number));
// add more ...
}

Слайд 68

Spring MVC Annotations
@ModelAttribute on method arguments

@PostMapping("/owners/{ownerId}/pets/{petId}/edit")
public String processSubmit(@ModelAttribute Pet pet) {

Spring MVC Annotations @ModelAttribute on method arguments @PostMapping("/owners/{ownerId}/pets/{petId}/edit") public String processSubmit(@ModelAttribute Pet pet) { }
}

Слайд 69

Content Negotiation

Content Negotiation

Слайд 70

Mapping of URLs, Validation support (JSR-349)
Configure JSR-349, “Bean Validation”

@Entity
@Table(name = "contact")
public

Mapping of URLs, Validation support (JSR-349) Configure JSR-349, “Bean Validation” @Entity @Table(name
class Contact implements Serializable {
private Long id;
private String firstName;
private String lastName;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@NotEmpty(message="{validation.firstname.NotEmpty.message}")
@Size(min=3, max=60, message="{validation.firstname.Size.message}")
@Column(name = "FIRST_NAME")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@NotEmpty(message="{validation.lastname.NotEmpty.message}")
@Size(min=1, max=40, message="{validation.lastname.Size.message}")
@Column(name = "LAST_NAME")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}

Слайд 71

Mapping of URLs, Validation support (JSR-349)
Configure JSR-349, “Bean Validation”

public String

Mapping of URLs, Validation support (JSR-349) Configure JSR-349, “Bean Validation” public String
update(@Valid Contact contact, ...
public String create(@Valid Contact contact, ...





Слайд 72

FILE UPLOAD HANDLING

FILE UPLOAD HANDLING

Слайд 73

File Upload Handling
Overview

Tomcat 7 -> Servlet 3.0 -> Spring 3.1

Apache

File Upload Handling Overview Tomcat 7 -> Servlet 3.0 -> Spring 3.1 Apache Commons FileUpload
Commons FileUpload

Слайд 74

File Upload Handling
Enable File Upload support



File Upload Handling Enable File Upload support

Слайд 75

File Upload Handling
Enable File Upload support



File Upload Handling Enable File Upload support

Слайд 76

File Upload Handling
Modifying Views for File Upload Support

File Upload Handling Modifying Views for File Upload Support

Слайд 77

File Upload Handling
Modifying Views for File Upload Support

File Upload Handling Modifying Views for File Upload Support

Слайд 78

File Upload Handling
Modifying Views for File Upload Support

File Upload Handling Modifying Views for File Upload Support

Слайд 79

SUPPORTING SERVLET 3.0 CODE-BASED (JAVA-BASED) CONFIGURATION

SUPPORTING SERVLET 3.0 CODE-BASED (JAVA-BASED) CONFIGURATION

Слайд 80

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration
Configuration

Advantages?

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration Configuration Advantages?

Слайд 81

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration
Configuration

Advantages?
Java синтаксис
Code IDE advantages
Flexibility
No need in full

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration Configuration Advantages? Java синтаксис Code IDE
build and redeploy

Слайд 82

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration
Configuration

org.springframework.web.WebApplicationInitializer

org.springframework.web.SpringServletContainerInitializer

Advantages?
Java синтаксис
Code IDE advantages
Flexibility
No need in full

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration Configuration org.springframework.web.WebApplicationInitializer org.springframework.web.SpringServletContainerInitializer Advantages? Java синтаксис
build and redeploy

Слайд 83

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration
Configuration

public class MyWebAppInitializer implements WebApplicationInitializer {
@Override

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration Configuration public class MyWebAppInitializer implements WebApplicationInitializer
public void onStartup(ServletContext container) throws ServletException {
XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml");
ServletRegistration.Dynamic dispatcher =
container.addServlet("appServlet", new DispatcherServlet(appContext));
MultipartConfigElement multipartConfigElement =
new MultipartConfigElement(null, 5000000, 5000000, 0);
dispatcher.setMultipartConfig(multipartConfigElement);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}

Слайд 84

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration
Configuration

public class MyWebAppInitializer implements WebApplicationInitializer {
@Override

Supporting Servlet 3.0 Code-Based (Java-Based) Configuration Configuration public class MyWebAppInitializer implements WebApplicationInitializer
public void onStartup(ServletContext container) throws ServletException {
XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml");
ServletRegistration.Dynamic dispatcher =
container.addServlet("appServlet", new DispatcherServlet(appContext));
MultipartConfigElement multipartConfigElement =
new MultipartConfigElement(null, 5000000, 5000000, 0);
dispatcher.setMultipartConfig(multipartConfigElement);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}


appServlet
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
/WEB-INF/spring/appServlet/servlet-context.xml

1

5000000



appServlet
/

Слайд 85

HANDLING EXCEPTIONS

HANDLING EXCEPTIONS

Слайд 86

Handling exceptions
Dealing with exceptions

Exceptions -> Status Codes
org.springframework.web.servlet.HandlerExceptionResolver: Exception -> ModelAndView
SimpleMappingExceptionResolver: Exceptions ->

Handling exceptions Dealing with exceptions Exceptions -> Status Codes org.springframework.web.servlet.HandlerExceptionResolver: Exception ->
Views
@ExceptionHandler, @ControllerAdvice
@ResponseStatus

Слайд 87

Handling exceptions
@ExceptionHandler & @ResponseStatus

@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(DataAccessException.class)
public void handleDataAccessError(DataAccessException ex) {}
@ResponseStatus(value = HttpStatus.PAYMENT_REQUIRED, message =

Handling exceptions @ExceptionHandler & @ResponseStatus @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(DataAccessException.class) public void handleDataAccessError(DataAccessException ex) {}
“I need money.”)
public class PaymentRequiredException {}

Слайд 88

SPRING MVC AND SPRING SECURITY

SPRING MVC AND SPRING SECURITY

Слайд 89

Spring MVC and Spring Security
Introduction

Declaration Security
Support for many authentication and authorization schemes,

Spring MVC and Spring Security Introduction Declaration Security Support for many authentication
such as basic, form-based, based on digests, JDBC and LDAP.
Support for security at the level of methods and security annotations JSR-250
Support for a one-time password
Container integration support
Supports anonymous sessions, simultaneous sessions, "remember me" mode, channel-level security and much more

Слайд 90

Spring MVC and Spring Security
Libraries

Maven Dependencies for Spring Security

Spring MVC and Spring Security Libraries Maven Dependencies for Spring Security

Слайд 91

Spring MVC and Spring Security
Configuring Spring Security

Configure a filter in the web

Spring MVC and Spring Security Configuring Spring Security Configure a filter in the web deployment descriptor:
deployment descriptor:

Слайд 92

Spring MVC and Spring Security
Configuring Spring Security

Spring MVC and Spring Security Configuring Spring Security

Слайд 93

Spring MVC and Spring Security
Adding Login Functions to the Application

Spring MVC and Spring Security Adding Login Functions to the Application

Слайд 94

Spring MVC and Spring Security
Enable Method-Level Security

-->

Слайд 95

Spring MVC and Spring Security
Enable Method-Level Security

-->

Слайд 96

HELPFUL LINKS

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
http://en.wikipedia.org/wiki/Spring_Framework#Model-view-controller_framework

HELPFUL LINKS http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller http://en.wikipedia.org/wiki/Spring_Framework#Model-view-controller_framework