没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架4.2.0参考文档(PDF版)
Spring框架4.2.0参考文档(PDF版)
5星 · 超过95%的资源 需积分: 10 41 下载量 38 浏览量
更新于2024-07-21
收藏 5.31MB PDF 举报
"Spring 4.2文档是一个详细的框架参考指南,由Spring的创始人和主要贡献者编写,包括Rod Johnson、Juergen Hoeller等人。这份文档是2015年8月发布的4.2.0.RELEASE版本,提供了一个完整的目录,便于用户查找和学习。文档覆盖了Spring Framework的主要特性和模块,强调了依赖注入和控制反转的概念,并介绍了Core Container、AOP和Instrumentation、Messaging以及Data Access等关键领域。"
Spring Framework是Java开发中广泛应用的开源框架,它提供了全面的企业级应用程序开发解决方案。在Spring 4.2中,以下几个关键知识点尤为突出:
1. **依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)**:这是Spring的核心特性,它允许开发者通过外部配置来管理对象之间的依赖关系,而不是在代码内部硬编码这些依赖。这增强了代码的可测试性、可维护性和解耦。
2. **Core Container**:包含Bean工厂(BeanFactory)和ApplicationContext,是Spring的基础。Bean工厂负责创建、配置和管理应用中的对象,而ApplicationContext则增加了对国际化、事件传播和AOP支持。
3. **AOP(面向切面编程)和Instrumentation**:AOP允许开发者定义“切面”,即关注点的模块化,如日志、事务管理等,可以跨多个对象执行。Instrumentation模块提供了类加载器级别的功能,用于代理生成和内存分析。
4. **Messaging**:Spring对消息传递系统的支持,如JMS(Java消息服务),使得应用能够实现异步处理和解耦。
5. **Data Access**:Spring提供了多种数据访问接口的抽象,包括JDBC、ORM(对象关系映射)框架如Hibernate和JPA,以及NoSQL数据库的支持。这使得开发者可以方便地切换不同的数据存储方案。
6. **Web Support**:Spring的Web模块提供了MVC(模型-视图-控制器)架构,用于构建Web应用程序,同时还支持RESTful服务和WebSocket等现代Web技术。
7. **Test Support**:Spring提供了强大的测试工具和框架,如Spring Test和Mockito,帮助开发者进行单元测试和集成测试。
8. **Spring Boot**:虽然不在4.2版本中,但值得注意的是,Spring Boot在此之后成为主流,它简化了Spring应用的启动和配置,是快速开发现代云应用的利器。
这份文档详细阐述了每个主题,并且有丰富的示例代码,适合Spring初学者和有经验的开发者深入理解框架的工作原理和最佳实践。对于想要精通Spring框架的人来说,这是一个不可或缺的学习资源。
Spring Framework Reference Documentation
4.2.0.RELEASE Spring Framework xvi
Request Parameters and Header Values ................................................. 480
Defining @RequestMapping handler methods .................................................. 480
Supported method argument types .......................................................... 480
Supported method return types ............................................................... 483
Binding request parameters to method parameters with @RequestParam ... 484
Mapping the request body with the @RequestBody annotation .................. 484
Mapping the response body with the @ResponseBody annotation ............. 485
Creating REST Controllers with the @RestController annotation ................ 486
Using HttpEntity ...................................................................................... 486
Using @ModelAttribute on a method ....................................................... 486
Using @ModelAttribute on a method argument ......................................... 487
Using @SessionAttributes to store model attributes in the HTTP session
between requests ................................................................................... 489
Working with "application/x-www-form-urlencoded" data ............................ 489
Mapping cookie values with the @CookieValue annotation ........................ 490
Mapping request header attributes with the @RequestHeader annotation ... 490
Method Parameters And Type Conversion ............................................... 491
Customizing WebDataBinder initialization ................................................. 491
Advising controllers with @ControllerAdvice ............................................. 492
Jackson Serialization View Support ......................................................... 493
Jackson JSONP Support ........................................................................ 494
Asynchronous Request Processing .................................................................. 495
Exception Handling for Async Requests ................................................... 496
Intercepting Async Requests ................................................................... 497
HTTP Streaming ..................................................................................... 497
HTTP Streaming With Server-Sent Events ............................................... 497
HTTP Streaming Directly To The OutputStream ....................................... 498
Configuring Asynchronous Request Processing ........................................ 498
Testing Controllers ......................................................................................... 499
21.4. Handler mappings .......................................................................................... 499
Intercepting requests with a HandlerInterceptor ................................................ 500
21.5. Resolving views ............................................................................................. 502
Resolving views with the ViewResolver interface .............................................. 502
Chaining ViewResolvers ................................................................................. 504
Redirecting to Views ....................................................................................... 504
RedirectView .......................................................................................... 505
The redirect: prefix ................................................................................. 506
The forward: prefix ................................................................................. 506
ContentNegotiatingViewResolver ..................................................................... 506
21.6. Using flash attributes ..................................................................................... 509
21.7. Building URIs ................................................................................................. 510
Building URIs to Controllers and methods ........................................................ 510
Building URIs to Controllers and methods from views ....................................... 511
21.8. Using locales ................................................................................................. 512
Obtaining Time Zone Information .................................................................... 513
AcceptHeaderLocaleResolver .......................................................................... 513
CookieLocaleResolver ..................................................................................... 513
SessionLocaleResolver ................................................................................... 513
LocaleChangeInterceptor ................................................................................ 513
21.9. Using themes ................................................................................................ 514
Spring Framework Reference Documentation
4.2.0.RELEASE Spring Framework xvii
Overview of themes ........................................................................................ 514
Defining themes ............................................................................................. 514
Theme resolvers ............................................................................................. 515
21.10. Spring’s multipart (file upload) support ........................................................... 515
Introduction .................................................................................................... 515
Using a MultipartResolver with Commons FileUpload ........................................ 516
Using a MultipartResolver with Servlet 3.0 ....................................................... 516
Handling a file upload in a form ...................................................................... 516
Handling a file upload request from programmatic clients .................................. 517
21.11. Handling exceptions ..................................................................................... 518
HandlerExceptionResolver .............................................................................. 518
@ExceptionHandler ........................................................................................ 519
Handling Standard Spring MVC Exceptions ...................................................... 519
Annotating Business Exceptions With @ResponseStatus .................................. 520
Customizing the Default Servlet Container Error Page ...................................... 520
21.12. Web Security ............................................................................................... 521
21.13. Convention over configuration support ........................................................... 521
The Controller ControllerClassNameHandlerMapping ........................................ 522
The Model ModelMap (ModelAndView) ............................................................ 523
The View - RequestToViewNameTranslator ..................................................... 524
21.14. HTTP caching support .................................................................................. 525
Cache-Control HTTP header ........................................................................... 525
HTTP caching support for static resources ....................................................... 526
Support for the Cache-Control, ETag and Last-Modified response headers in
Controllers ...................................................................................................... 526
Shallow ETag support ..................................................................................... 527
21.15. Code-based Servlet container initialization ..................................................... 528
21.16. Configuring Spring MVC ............................................................................... 530
Enabling the MVC Java Config or the MVC XML Namespace ............................ 530
Customizing the Provided Configuration ........................................................... 531
Conversion and Formatting ............................................................................. 532
Validation ....................................................................................................... 533
Interceptors .................................................................................................... 534
Content Negotiation ........................................................................................ 534
View Controllers ............................................................................................. 535
View Resolvers .............................................................................................. 536
Serving of Resources ..................................................................................... 537
Falling Back On the "Default" Servlet To Serve Resources ................................ 539
Path Matching ................................................................................................ 540
Advanced Customizations with MVC Java Config ............................................. 541
Advanced Customizations with the MVC Namespace ........................................ 542
22. View technologies ..................................................................................................... 543
22.1. Introduction .................................................................................................... 543
22.2. Thymeleaf ..................................................................................................... 543
22.3. Groovy Markup Templates .............................................................................. 543
Configuration .................................................................................................. 543
Example ......................................................................................................... 544
22.4. Velocity & FreeMarker .................................................................................... 544
Dependencies ................................................................................................ 544
Context configuration ...................................................................................... 544
Spring Framework Reference Documentation
4.2.0.RELEASE Spring Framework xviii
Creating templates ......................................................................................... 545
Advanced configuration ................................................................................... 545
velocity.properties ................................................................................... 545
FreeMarker ............................................................................................. 546
Bind support and form handling ....................................................................... 546
The bind macros .................................................................................... 546
Simple binding ........................................................................................ 546
Form input generation macros ................................................................. 547
HTML escaping and XHTML compliance ................................................. 551
22.5. JSP & JSTL .................................................................................................. 551
View resolvers ................................................................................................ 551
'Plain-old' JSPs versus JSTL ........................................................................... 552
Additional tags facilitating development ............................................................ 552
Using Spring’s form tag library ........................................................................ 552
Configuration .......................................................................................... 553
The form tag .......................................................................................... 553
The input tag .......................................................................................... 554
The checkbox tag ................................................................................... 554
The checkboxes tag ............................................................................... 556
The radiobutton tag ................................................................................ 556
The radiobuttons tag ............................................................................... 556
The password tag ................................................................................... 557
The select tag ........................................................................................ 557
The option tag ........................................................................................ 557
The options tag ...................................................................................... 558
The textarea tag ..................................................................................... 559
The hidden tag ....................................................................................... 559
The errors tag ........................................................................................ 559
HTTP Method Conversion ....................................................................... 561
HTML5 Tags .......................................................................................... 562
22.6. Script templates ............................................................................................. 562
Dependencies ................................................................................................ 562
How to integrate script based templating .......................................................... 563
22.7. XML Marshalling View .................................................................................... 565
22.8. Tiles .............................................................................................................. 565
Dependencies ................................................................................................ 565
How to integrate Tiles ..................................................................................... 565
UrlBasedViewResolver ............................................................................ 566
ResourceBundleViewResolver ................................................................. 566
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 567
22.9. XSLT ............................................................................................................. 567
My First Words ............................................................................................... 567
Bean definitions ...................................................................................... 567
Standard MVC controller code ................................................................. 568
Document transformation ........................................................................ 568
22.10. Document views (PDF/Excel) ........................................................................ 569
Introduction .................................................................................................... 569
Configuration and setup .................................................................................. 569
Document view definitions ....................................................................... 569
Controller code ....................................................................................... 570
Spring Framework Reference Documentation
4.2.0.RELEASE Spring Framework xix
Subclassing for Excel views .................................................................... 570
Subclassing for PDF views ..................................................................... 571
22.11. JasperReports .............................................................................................. 571
Dependencies ................................................................................................ 572
Configuration .................................................................................................. 572
Configuring the ViewResolver .................................................................. 572
Configuring the Views ............................................................................. 572
About Report Files .................................................................................. 573
Using JasperReportsMultiFormatView ...................................................... 573
Populating the ModelAndView ......................................................................... 574
Working with Sub-Reports ............................................................................... 575
Configuring Sub-Report Files .................................................................. 575
Configuring Sub-Report Data Sources ..................................................... 575
Configuring Exporter Parameters ..................................................................... 576
22.12. Feed Views ................................................................................................. 576
22.13. JSON Mapping View .................................................................................... 577
22.14. XML Mapping View ...................................................................................... 577
23. Integrating with other web frameworks ....................................................................... 578
23.1. Introduction .................................................................................................... 578
23.2. Common configuration ................................................................................... 579
23.3. JavaServer Faces 1.2 .................................................................................... 580
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 580
FacesContextUtils ........................................................................................... 580
23.4. Apache Struts 2.x .......................................................................................... 580
23.5. Tapestry 5.x .................................................................................................. 581
23.6. Further Resources ......................................................................................... 581
24. Portlet MVC Framework ............................................................................................ 582
24.1. Introduction .................................................................................................... 582
Controllers - The C in MVC ............................................................................ 583
Views - The V in MVC .................................................................................... 583
Web-scoped beans ......................................................................................... 583
24.2. The DispatcherPortlet ..................................................................................... 583
24.3. The ViewRendererServlet ............................................................................... 585
24.4. Controllers ..................................................................................................... 586
AbstractController and PortletContentGenerator ............................................... 587
Other simple controllers .................................................................................. 588
Command Controllers ..................................................................................... 588
PortletWrappingController ................................................................................ 589
24.5. Handler mappings .......................................................................................... 589
PortletModeHandlerMapping ............................................................................ 590
ParameterHandlerMapping .............................................................................. 590
PortletModeParameterHandlerMapping ............................................................ 591
Adding HandlerInterceptors ............................................................................. 591
HandlerInterceptorAdapter ............................................................................... 592
ParameterMappingInterceptor .......................................................................... 592
24.6. Views and resolving them .............................................................................. 592
24.7. Multipart (file upload) support ......................................................................... 592
Using the PortletMultipartResolver ................................................................... 593
Handling a file upload in a form ...................................................................... 593
24.8. Handling exceptions ....................................................................................... 597
Spring Framework Reference Documentation
4.2.0.RELEASE Spring Framework xx
24.9. Annotation-based controller configuration ........................................................ 597
Setting up the dispatcher for annotation support ............................................... 597
Defining a controller with @Controller .............................................................. 598
Mapping requests with @RequestMapping ....................................................... 598
Supported handler method arguments ............................................................. 600
Binding request parameters to method parameters with @RequestParam .......... 601
Providing a link to data from the model with @ModelAttribute ............................ 601
Specifying attributes to store in a Session with @SessionAttributes .................... 602
Customizing WebDataBinder initialization ......................................................... 602
Customizing data binding with @InitBinder ............................................... 603
Configuring a custom WebBindingInitializer .............................................. 603
24.10. Portlet application deployment ...................................................................... 603
25. WebSocket Support .................................................................................................. 605
25.1. Introduction .................................................................................................... 605
WebSocket Fallback Options ........................................................................... 605
A Messaging Architecture ............................................................................... 606
Sub-Protocol Support in WebSocket ................................................................ 606
Should I Use WebSocket? .............................................................................. 606
25.2. WebSocket API ............................................................................................. 607
Create and Configure a WebSocketHandler ..................................................... 607
Customizing the WebSocket Handshake .......................................................... 608
WebSocketHandler Decoration ........................................................................ 609
Deployment Considerations ............................................................................. 609
Configuring the WebSocket Engine ................................................................. 610
Configuring allowed origins ............................................................................. 612
25.3. SockJS Fallback Options ................................................................................ 613
Overview of SockJS ....................................................................................... 613
Enable SockJS ............................................................................................... 614
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 615
Heartbeat Messages ....................................................................................... 616
Servlet 3 Async Requests ............................................................................... 616
CORS Headers for SockJS ............................................................................. 617
SockJS Client ................................................................................................. 617
25.4. STOMP Over WebSocket Messaging Architecture ........................................... 619
Overview of STOMP ....................................................................................... 619
Enable STOMP over WebSocket ..................................................................... 620
Flow of Messages .......................................................................................... 622
Annotation Message Handling ......................................................................... 624
Sending Messages ......................................................................................... 625
Simple Broker ................................................................................................ 626
Full-Featured Broker ....................................................................................... 626
Connections To Full-Featured Broker .............................................................. 627
Using Dot as Separator in @MessageMapping Destinations .............................. 628
Authentication ................................................................................................. 629
User Destinations ........................................................................................... 630
Listening To ApplicationContext Events and Intercepting Messages ................... 631
STOMP Client ................................................................................................ 633
WebSocket Scope .......................................................................................... 634
Configuration and Performance ....................................................................... 635
Runtime Monitoring ......................................................................................... 638
剩余884页未读,继续阅读
点击了解资源详情
282 浏览量
点击了解资源详情
2018-11-27 上传
2010-09-15 上传
157 浏览量
721 浏览量
2016-01-24 上传
163 浏览量
sinat_19326139
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功