Академический Документы
Профессиональный Документы
Культура Документы
3.0
Speaker Qualifications
SOA/Enterprise Architect Developer (Java, C++, C#, Objective-C) Instructor (VisiBroker, RUP, OOAD) Speaker (NFJS, JavaOne, JAX-India) Involved in Java since 1996 Author (Pro Spring 3.0)
Agenda
Agenda
Introduction to IoC
<<uses>>
<<uses>>
Introduction to IoC
<<uses>>
<<uses>>
Introduction to IoC
<<uses>>
<<uses>>
Spring IoC
<<uses>>
<<uses>>
<creates>
Client:
XML Configuration
Types of Injections
values are injected through the constructor at object construction object is created, then values are set through each property setter object is created, then the values are (usually) reflectively set on the field (by passing the setter)
8
Setter
Field
Spring Annotations
@Component **
Indicates that a class is a component Class is a candidate for auto-detection Custom component extensions
@Controller
Specialized Component
@Repository
@Service
@Autowired
Marks a constructor, field, setter or config method for injection. Fields are injected After construction
@Autowired(required=false)
@Qualifier
Qualifies a bean for autowiring May be customized
@Required
Types of Injections
Constructor
Setter
Field
12
configuration method
13
Spring MVC
Spring Web
Spring JavaScript
support for stateful interactions
Spring Faces
support jsr-168 and jsr-286 support
15
Spring Portlet
Portlet
MVC Overview
Improves
16
Model
data
container
a simple map
View
typically
Controller
controlling
17
data access
render
DB
18
DispatcherServlet
Spring
Controllers
User
TIP: 1. Delegate to service beans for business logic 2. handle only navigation
View
Responsible
19
ModelAndView
stores
ViewResolver
Used
HandlerMapping
Strategy
Spring Views
Extensive Support
JSP,
21
Spring View
22
23
24
25
26
@Controller
Stereotype used to Controller of MVC Scanned for RequestMappings
@RequestMapping
Annotates a handler method for a request Very flexible
@RequestParam
Annotates that a method parameter should be bound to a web request parameter Marks session attributes that a handler uses
SessionAttributes
30
31
31
31
32
Parameters can be
Request / response / session WebRequest InputStream OutputStream @RequestParam +++ ModelAndView Object Model Object Map for exposing model View Object String which is a view name Void if method wrote the response content directly
Return types
another refactor: just return the model data, view is assumed through convention.
36
Added to Model
37
Multi-Action Convention
/hotel/index
/hotel/show
/hotel/list
38
Parameters
/hotel/show?id=42
39
URL Autonomy
http://<host>:<port>/petclinic/main/owner/show
Web Application/Servlet/Controller/method
41
DispatcherServlet
42
DispatcherServlet
42
Handler Mappings
DefaultAnnotationHandlerMapping
annotation
based - @Controller
SimpleUrlHandlerMapping
configuration
ControllerClassNameHandlerMapping UrlFileNameViewController
views
without a controller
43
44
Mapping by Controller
45
Mapping by Convention
46
47
/petclinic/main/owner/show
org...petclinic.Owner
48
/petclinic/main/patient/owner/show
org...petclinic.Owner
49
/petclinic/main/patient/owner/show
prefix org...petclinic.Owner
50
@RequestMapping
51
/owner, /owner/*
GET /owner/find?submit=
52
Show owner: GET /owner/show Add or edit owner: GET /owner/form GET /owner/form?id= POST /owner/form Search owner: GET /owner/find GET /owner/find?submit=
53
@RequestParam
type conversion
GET
/owner/show?submit=2
55
@PathVariable - RESTFUL
GET
/owner/show/2
56
57
Implicit Model
TIP: If you need more than one model attribute, take model as a input argument
58
59
60
Spring Forms
62
Submitting Forms
63
Model Validation
64
65
Summary
References
Spring Framework: http://www.springsource.com/download/ community?project=Spring%20Framework Spring Docs: http://www.springsource.org/documentation Session Source Code: http://groups.google.com/group/codemash