没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring Framework 4.2.2.RELEASE:官方参考文档
Spring Framework 4.2.2.RELEASE:官方参考文档
需积分: 9 2 下载量 58 浏览量
更新于2024-07-21
收藏 5.32MB PDF 举报
"Spring Framework 4.2.2.RELEASE 的最新帮助文档"
Spring Framework 是一个广泛使用的开源Java应用程序开发框架,由Rod Johnson等人创建。它以其依赖注入(Dependency Injection,DI)和控制反转(Inversion of Control,IoC)的概念为核心,提供了多种模块化的功能,以支持企业级应用的开发。4.2.2.RELEASE是该框架的一个版本,包含了从4.2.2开始的一系列更新和改进。
### 1. 概览
**1.1 获取Spring的开始**
Spring Framework的入门通常涉及下载或通过Maven/Gradle等构建工具添加依赖。开发者需要了解如何配置项目,包括引入Spring的核心库,以及如何设置Spring的配置文件,如`applicationContext.xml`,来定义bean及其依赖关系。
**1.2 Spring Framework简介**
Spring框架由多个模块组成,这些模块可以单独使用,也可以组合使用,以满足不同的需求。核心模块包括核心容器、面向切面编程(AOP)和工具支持,还有其他如数据访问、Web、消息传递等模块。
### 2. 核心概念
**2.1 依赖注入和控制反转**
DI和IoC是Spring的核心设计理念。DI允许组件之间的依赖关系在运行时通过容器来管理,而不是在代码中硬编码。这样可以提高代码的可测试性和可维护性,因为对象的实例化和组装由框架负责,而不是由对象自身负责。
**2.2 模块**
- **核心容器**:包括Core、 Beans、Context和Expression Language模块,提供了DI的基础,bean的生命周期管理和上下文支持。
- **AOP和Instrumentation**:支持面向切面编程,允许开发者创建切面来封装横切关注点,如日志、事务管理等。Instrumentation模块则提供了类加载器和内存分析工具的支持。
- **Messaging**:通常与Spring的Message Broker集成,如JMS,提供消息驱动的应用支持。
- **数据访问**:涵盖了对数据库的支持,如JDBC、ORM(Hibernate、JPA等)和OXM(Object/XML Mapping)。
- **Web**:包括Web-Servlet和Web-Portlet模块,支持MVC模式的Web应用开发。
### 3. 使用Spring
Spring框架提供了丰富的API和工具,例如用于处理HTTP请求的Spring MVC,用于数据库操作的JdbcTemplate,以及用于事务管理的PlatformTransactionManager。此外,Spring还支持声明式事务管理,基于注解的控制器,以及用于单元测试和集成测试的测试框架。
### 4. 更新与改进
4.2.2.RELEASE版本可能包含了错误修复、性能优化和新特性的添加。开发者应该查阅官方的发行说明以了解具体细节。
### 5. 社区与支持
Spring Framework拥有活跃的社区,包括论坛、邮件列表、Stack Overflow等,以及详细的官方文档,使得开发者能够获取到最新的信息、示例代码和问题解答。
Spring Framework 4.2.2.RELEASE作为一个全面的开发框架,为企业级Java应用开发提供了强大的支持,其依赖注入、模块化设计以及广泛的社区支持,使得它成为许多开发者和组织的首选框架。
Spring Framework Reference Documentation
4.2.2.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 ..................................................................................... 508
21.7. Building URIs ................................................................................................. 509
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 .................................................................... 512
AcceptHeaderLocaleResolver .......................................................................... 512
CookieLocaleResolver ..................................................................................... 512
SessionLocaleResolver ................................................................................... 513
LocaleChangeInterceptor ................................................................................ 513
21.9. Using themes ................................................................................................ 513
Spring Framework Reference Documentation
4.2.2.RELEASE Spring Framework xvii
Overview of themes ........................................................................................ 513
Defining themes ............................................................................................. 513
Theme resolvers ............................................................................................. 514
21.10. Spring’s multipart (file upload) support ........................................................... 515
Introduction .................................................................................................... 515
Using a MultipartResolver with Commons FileUpload ........................................ 515
Using a MultipartResolver with Servlet 3.0 ....................................................... 515
Handling a file upload in a form ...................................................................... 516
Handling a file upload request from programmatic clients .................................. 517
21.11. Handling exceptions ..................................................................................... 517
HandlerExceptionResolver .............................................................................. 517
@ExceptionHandler ........................................................................................ 518
Handling Standard Spring MVC Exceptions ...................................................... 518
Annotating Business Exceptions With @ResponseStatus .................................. 519
Customizing the Default Servlet Container Error Page ...................................... 520
21.12. Web Security ............................................................................................... 520
21.13. Convention over configuration support ........................................................... 520
The Controller ControllerClassNameHandlerMapping ........................................ 521
The Model ModelMap (ModelAndView) ............................................................ 522
The View - RequestToViewNameTranslator ..................................................... 523
21.14. HTTP caching support .................................................................................. 524
Cache-Control HTTP header ........................................................................... 525
HTTP caching support for static resources ....................................................... 525
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 ..................................................... 527
21.16. Configuring Spring MVC ............................................................................... 529
Enabling the MVC Java Config or the MVC XML Namespace ............................ 529
Customizing the Provided Configuration ........................................................... 531
Conversion and Formatting ............................................................................. 531
Validation ....................................................................................................... 532
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
Message Converters ....................................................................................... 541
Advanced Customizations with MVC Java Config ............................................. 542
Advanced Customizations with the MVC Namespace ........................................ 543
22. View technologies ..................................................................................................... 544
22.1. Introduction .................................................................................................... 544
22.2. Thymeleaf ..................................................................................................... 544
22.3. Groovy Markup Templates .............................................................................. 544
Configuration .................................................................................................. 544
Example ......................................................................................................... 545
22.4. Velocity & FreeMarker .................................................................................... 545
Dependencies ................................................................................................ 545
Spring Framework Reference Documentation
4.2.2.RELEASE Spring Framework xviii
Context configuration ...................................................................................... 545
Creating templates ......................................................................................... 546
Advanced configuration ................................................................................... 546
velocity.properties ................................................................................... 546
FreeMarker ............................................................................................. 547
Bind support and form handling ....................................................................... 547
The bind macros .................................................................................... 547
Simple binding ........................................................................................ 547
Form input generation macros ................................................................. 548
HTML escaping and XHTML compliance ................................................. 552
22.5. JSP & JSTL .................................................................................................. 552
View resolvers ................................................................................................ 552
'Plain-old' JSPs versus JSTL ........................................................................... 553
Additional tags facilitating development ............................................................ 553
Using Spring’s form tag library ........................................................................ 553
Configuration .......................................................................................... 554
The form tag .......................................................................................... 554
The input tag .......................................................................................... 555
The checkbox tag ................................................................................... 555
The checkboxes tag ............................................................................... 557
The radiobutton tag ................................................................................ 557
The radiobuttons tag ............................................................................... 557
The password tag ................................................................................... 558
The select tag ........................................................................................ 558
The option tag ........................................................................................ 558
The options tag ...................................................................................... 559
The textarea tag ..................................................................................... 560
The hidden tag ....................................................................................... 560
The errors tag ........................................................................................ 560
HTTP Method Conversion ....................................................................... 562
HTML5 Tags .......................................................................................... 563
22.6. Script templates ............................................................................................. 563
Dependencies ................................................................................................ 563
How to integrate script based templating .......................................................... 564
22.7. XML Marshalling View .................................................................................... 566
22.8. Tiles .............................................................................................................. 566
Dependencies ................................................................................................ 566
How to integrate Tiles ..................................................................................... 566
UrlBasedViewResolver ............................................................................ 567
ResourceBundleViewResolver ................................................................. 567
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 568
22.9. XSLT ............................................................................................................. 568
My First Words ............................................................................................... 569
Bean definitions ...................................................................................... 569
Standard MVC controller code ................................................................. 569
Document transformation ........................................................................ 570
22.10. Document views (PDF/Excel) ........................................................................ 570
Introduction .................................................................................................... 570
Configuration and setup .................................................................................. 571
Document view definitions ....................................................................... 571
Spring Framework Reference Documentation
4.2.2.RELEASE Spring Framework xix
Controller code ....................................................................................... 571
Subclassing for Excel views .................................................................... 571
Subclassing for PDF views ..................................................................... 573
22.11. JasperReports .............................................................................................. 573
Dependencies ................................................................................................ 573
Configuration .................................................................................................. 573
Configuring the ViewResolver .................................................................. 574
Configuring the Views ............................................................................. 574
About Report Files .................................................................................. 574
Using JasperReportsMultiFormatView ...................................................... 574
Populating the ModelAndView ......................................................................... 575
Working with Sub-Reports ............................................................................... 576
Configuring Sub-Report Files .................................................................. 576
Configuring Sub-Report Data Sources ..................................................... 577
Configuring Exporter Parameters ..................................................................... 577
22.12. Feed Views ................................................................................................. 578
22.13. JSON Mapping View .................................................................................... 578
22.14. XML Mapping View ...................................................................................... 579
23. Integrating with other web frameworks ....................................................................... 580
23.1. Introduction .................................................................................................... 580
23.2. Common configuration ................................................................................... 581
23.3. JavaServer Faces 1.2 .................................................................................... 582
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 582
FacesContextUtils ........................................................................................... 582
23.4. Apache Struts 2.x .......................................................................................... 582
23.5. Tapestry 5.x .................................................................................................. 583
23.6. Further Resources ......................................................................................... 583
24. Portlet MVC Framework ............................................................................................ 584
24.1. Introduction .................................................................................................... 584
Controllers - The C in MVC ............................................................................ 585
Views - The V in MVC .................................................................................... 585
Web-scoped beans ......................................................................................... 585
24.2. The DispatcherPortlet ..................................................................................... 585
24.3. The ViewRendererServlet ............................................................................... 587
24.4. Controllers ..................................................................................................... 588
AbstractController and PortletContentGenerator ............................................... 589
Other simple controllers .................................................................................. 590
Command Controllers ..................................................................................... 590
PortletWrappingController ................................................................................ 591
24.5. Handler mappings .......................................................................................... 591
PortletModeHandlerMapping ............................................................................ 592
ParameterHandlerMapping .............................................................................. 592
PortletModeParameterHandlerMapping ............................................................ 593
Adding HandlerInterceptors ............................................................................. 593
HandlerInterceptorAdapter ............................................................................... 594
ParameterMappingInterceptor .......................................................................... 594
24.6. Views and resolving them .............................................................................. 594
24.7. Multipart (file upload) support ......................................................................... 594
Using the PortletMultipartResolver ................................................................... 595
Handling a file upload in a form ...................................................................... 595
Spring Framework Reference Documentation
4.2.2.RELEASE Spring Framework xx
24.8. Handling exceptions ....................................................................................... 599
24.9. Annotation-based controller configuration ........................................................ 599
Setting up the dispatcher for annotation support ............................................... 599
Defining a controller with @Controller .............................................................. 600
Mapping requests with @RequestMapping ....................................................... 600
Supported handler method arguments ............................................................. 602
Binding request parameters to method parameters with @RequestParam .......... 604
Providing a link to data from the model with @ModelAttribute ............................ 604
Specifying attributes to store in a Session with @SessionAttributes .................... 605
Customizing WebDataBinder initialization ......................................................... 605
Customizing data binding with @InitBinder ............................................... 605
Configuring a custom WebBindingInitializer .............................................. 606
24.10. Portlet application deployment ...................................................................... 606
25. WebSocket Support .................................................................................................. 607
25.1. Introduction .................................................................................................... 607
WebSocket Fallback Options ........................................................................... 607
A Messaging Architecture ............................................................................... 608
Sub-Protocol Support in WebSocket ................................................................ 608
Should I Use WebSocket? .............................................................................. 608
25.2. WebSocket API ............................................................................................. 609
Create and Configure a WebSocketHandler ..................................................... 609
Customizing the WebSocket Handshake .......................................................... 610
WebSocketHandler Decoration ........................................................................ 611
Deployment Considerations ............................................................................. 611
Configuring the WebSocket Engine ................................................................. 612
Configuring allowed origins ............................................................................. 614
25.3. SockJS Fallback Options ................................................................................ 615
Overview of SockJS ....................................................................................... 615
Enable SockJS ............................................................................................... 616
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 617
Heartbeat Messages ....................................................................................... 618
Servlet 3 Async Requests ............................................................................... 618
CORS Headers for SockJS ............................................................................. 619
SockJS Client ................................................................................................. 619
25.4. STOMP Over WebSocket Messaging Architecture ........................................... 621
Overview of STOMP ....................................................................................... 621
Enable STOMP over WebSocket ..................................................................... 622
Flow of Messages .......................................................................................... 624
Annotation Message Handling ......................................................................... 626
Sending Messages ......................................................................................... 628
Simple Broker ................................................................................................ 628
Full-Featured Broker ....................................................................................... 628
Connections To Full-Featured Broker .............................................................. 629
Using Dot as Separator in @MessageMapping Destinations .............................. 630
Authentication ................................................................................................. 631
User Destinations ........................................................................................... 632
Listening To ApplicationContext Events and Intercepting Messages ................... 633
STOMP Client ................................................................................................ 635
WebSocket Scope .......................................................................................... 636
Configuration and Performance ....................................................................... 637
剩余886页未读,继续阅读
2017-09-03 上传
2015-10-29 上传
2018-09-10 上传
zengjinghu001
- 粉丝: 5
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- react-mobx-sample:React Mobx示例应用程序
- 行业分类-设备装置-航天器姿态控制系统的间歇性故障容错分析方法.zip
- Timer
- booInvestments.github.io:CS 422 Stratton Oakmont网站
- new1
- Clean WeChat X.exe
- Project3
- MM32SPIN0x(q) 库函数和例程.rar
- tuneout:一个 Apple 脚本,用于将 iTunes 歌曲和艺术家信息写入文本文件,以便与 OBS 流媒体软件的“文件中的文本”功能一起使用。 TuneOut 和 OBS 一起使用,将在流期间显示 iTunes 正在播放的信息
- NASS-SBoH-2021-1-client-server:客户端服务器
- 套接字服务器
- G2M-insight-for-Cab-Investment-firm-
- money-back-guarantee-contract
- 行业分类-设备装置-航天光学遥感器在轨连续调焦的闭环动态仿真测试方法.zip
- Python库 | sqlalchemy_drill-0.2.1.dev0-py3-none-any.whl
- java版商城源码-mgmsmartcity:管理智慧城市
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功