没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架官方参考文档5.0.0.BUILD-SNAPSHOT
Spring框架官方参考文档5.0.0.BUILD-SNAPSHOT
需积分: 7 1 下载量 170 浏览量
更新于2024-07-17
收藏 5.21MB PDF 举报
"Spring框架官方参考文档"
Spring框架是Java开发中的一个核心库,它提供了全面的基础设施支持,用于创建企业级应用。这份文档是Spring Framework 5.0.0.BUILD-SNAPSHOT版本的官方指南,由众多贡献者如Rod Johnson、Juergen Hoeller等人共同编撰,版权归属2004年至2016年。
文档概述了Spring框架的主要功能和设计理念,旨在帮助开发者更好地理解和使用Spring。以下是文档的部分内容概览:
1. **入门指南** - 这部分介绍如何开始使用Spring,包括如何设置项目环境,添加依赖,以及基本的配置步骤。对于初学者来说,这是了解Spring的第一步。
2. **Spring框架简介** - 该章节深入讨论了Spring的核心特性,其中两个关键概念是Dependency Injection(依赖注入)和Inversion of Control(控制反转)。依赖注入允许对象之间的耦合度降低,使代码更易于测试和维护。控制反转则是Spring实现这一目标的一种策略,它将对象的创建和管理交由框架处理。
3. **模块划分** - Spring框架分为多个模块,包括:
- **核心容器(Core Container)** - 包括 Beans、Core、Context 模块,提供Spring的基本功能,如bean的定义、配置和管理,以及应用上下文。
- **AOP和Instrumentation** - AOP(面向切面编程)模块支持在运行时实现横切关注点,如日志、事务管理等。Instrumentation模块则提供类加载器和应用程序类的监控。
4. **其他模块** - Spring还包括Data Access/Integration(数据访问/集成)、Web、Test等模块,分别涵盖了数据库访问、Web应用支持和测试框架等内容。
文档进一步详细介绍了每个模块的功能、配置方法和使用示例。例如,Core Container模块中会详细阐述XML和Java配置,以及如何声明和管理bean。AOP模块会解释如何定义切面,以及切点表达式的工作方式。Web模块则涵盖了Spring MVC,它是构建RESTful Web服务的强大工具。
此外,文档还可能涉及Spring的安全、消息传递、任务调度等多个方面,提供完整的API参考和使用指导。对于开发者来说,这是一个不可或缺的参考资料,无论你是初学者还是经验丰富的专业人士,都能从中找到你需要的信息,提升你的Spring应用开发技能。
Spring Framework Reference Documentation
5.0.0.BUILD-SNAPSHOT Spring Framework xvi
Mapping the request body with the @RequestBody annotation .................. 474
Mapping the response body with the @ResponseBody annotation ............. 475
Creating REST Controllers with the @RestController annotation ................ 476
Using HttpEntity ...................................................................................... 476
Using @ModelAttribute on a method ....................................................... 476
Using @ModelAttribute on a method argument ......................................... 477
Using @SessionAttributes to store model attributes in the HTTP session
between requests ................................................................................... 479
Using @SessionAttribute to access pre-existing global session attributes .... 480
Using @RequestAttribute to access request attributes .............................. 480
Working with "application/x-www-form-urlencoded" data ............................ 480
Mapping cookie values with the @CookieValue annotation ........................ 481
Mapping request header attributes with the @RequestHeader annotation ... 481
Method Parameters And Type Conversion ............................................... 482
Customizing WebDataBinder initialization ................................................. 482
Advising controllers with @ControllerAdvice and @RestControllerAdvice .... 483
Jackson Serialization View Support ......................................................... 484
Jackson JSONP Support ........................................................................ 485
Asynchronous Request Processing .................................................................. 486
Exception Handling for Async Requests ................................................... 487
Intercepting Async Requests ................................................................... 488
HTTP Streaming ..................................................................................... 488
HTTP Streaming With Server-Sent Events ............................................... 488
HTTP Streaming Directly To The OutputStream ....................................... 489
Configuring Asynchronous Request Processing ........................................ 489
Testing Controllers ......................................................................................... 490
18.4. Handler mappings .......................................................................................... 490
Intercepting requests with a HandlerInterceptor ................................................ 491
18.5. Resolving views ............................................................................................. 493
Resolving views with the ViewResolver interface .............................................. 493
Chaining ViewResolvers ................................................................................. 495
Redirecting to Views ....................................................................................... 495
RedirectView .......................................................................................... 496
The redirect: prefix ................................................................................. 497
The forward: prefix ................................................................................. 497
ContentNegotiatingViewResolver ..................................................................... 497
18.6. Using flash attributes ..................................................................................... 499
18.7. Building URIs ................................................................................................. 500
Building URIs to Controllers and methods ........................................................ 501
Building URIs to Controllers and methods from views ....................................... 502
18.8. Using locales ................................................................................................. 503
Obtaining Time Zone Information .................................................................... 503
AcceptHeaderLocaleResolver .......................................................................... 503
CookieLocaleResolver ..................................................................................... 503
SessionLocaleResolver ................................................................................... 504
LocaleChangeInterceptor ................................................................................ 504
18.9. Using themes ................................................................................................ 504
Overview of themes ........................................................................................ 504
Defining themes ............................................................................................. 505
Theme resolvers ............................................................................................. 505
Spring Framework Reference Documentation
5.0.0.BUILD-SNAPSHOT Spring Framework xvii
18.10. Spring’s multipart (file upload) support ........................................................... 506
Introduction .................................................................................................... 506
Using a MultipartResolver with Commons FileUpload ........................................ 506
Using a MultipartResolver with Servlet 3.0 ....................................................... 506
Handling a file upload in a form ...................................................................... 507
Handling a file upload request from programmatic clients .................................. 508
18.11. Handling exceptions ..................................................................................... 509
HandlerExceptionResolver .............................................................................. 509
@ExceptionHandler ........................................................................................ 509
Handling Standard Spring MVC Exceptions ...................................................... 510
Annotating Business Exceptions With @ResponseStatus .................................. 511
Customizing the Default Servlet Container Error Page ...................................... 511
18.12. Web Security ............................................................................................... 512
18.13. Convention over configuration support ........................................................... 512
The Controller ControllerClassNameHandlerMapping ........................................ 512
The Model ModelMap (ModelAndView) ............................................................ 513
The View - RequestToViewNameTranslator ..................................................... 514
18.14. HTTP caching support .................................................................................. 515
Cache-Control HTTP header ........................................................................... 516
HTTP caching support for static resources ....................................................... 516
Support for the Cache-Control, ETag and Last-Modified response headers in
Controllers ...................................................................................................... 517
Shallow ETag support ..................................................................................... 518
18.15. Code-based Servlet container initialization ..................................................... 519
18.16. Configuring Spring MVC ............................................................................... 520
Enabling the MVC Java Config or the MVC XML Namespace ............................ 521
Customizing the Provided Configuration ........................................................... 522
Conversion and Formatting ............................................................................. 523
Validation ....................................................................................................... 524
Interceptors .................................................................................................... 525
Content Negotiation ........................................................................................ 526
View Controllers ............................................................................................. 527
View Resolvers .............................................................................................. 527
Serving of Resources ..................................................................................... 528
Falling Back On the "Default" Servlet To Serve Resources ................................ 531
Path Matching ................................................................................................ 532
Message Converters ....................................................................................... 533
Advanced Customizations with MVC Java Config ............................................. 534
Advanced Customizations with the MVC Namespace ........................................ 535
19. View technologies ..................................................................................................... 536
19.1. Introduction .................................................................................................... 536
19.2. Thymeleaf ..................................................................................................... 536
19.3. Groovy Markup Templates .............................................................................. 536
Configuration .................................................................................................. 536
Example ......................................................................................................... 537
19.4. FreeMarker .................................................................................................... 537
Dependencies ................................................................................................ 537
Context configuration ...................................................................................... 537
Creating templates ......................................................................................... 537
Advanced FreeMarker configuration ................................................................. 538
Spring Framework Reference Documentation
5.0.0.BUILD-SNAPSHOT Spring Framework xviii
Bind support and form handling ....................................................................... 538
The bind macros .................................................................................... 538
Simple binding ........................................................................................ 538
Form input generation macros ................................................................. 539
HTML escaping and XHTML compliance ................................................. 543
19.5. JSP & JSTL .................................................................................................. 543
View resolvers ................................................................................................ 543
'Plain-old' JSPs versus JSTL ........................................................................... 544
Additional tags facilitating development ............................................................ 544
Using Spring’s form tag library ........................................................................ 544
Configuration .......................................................................................... 544
The form tag .......................................................................................... 545
The input tag .......................................................................................... 546
The checkbox tag ................................................................................... 546
The checkboxes tag ............................................................................... 548
The radiobutton tag ................................................................................ 548
The radiobuttons tag ............................................................................... 548
The password tag ................................................................................... 549
The select tag ........................................................................................ 549
The option tag ........................................................................................ 549
The options tag ...................................................................................... 550
The textarea tag ..................................................................................... 551
The hidden tag ....................................................................................... 551
The errors tag ........................................................................................ 551
HTTP Method Conversion ....................................................................... 553
HTML5 Tags .......................................................................................... 554
19.6. Script templates ............................................................................................. 554
Dependencies ................................................................................................ 554
How to integrate script based templating .......................................................... 555
19.7. XML Marshalling View .................................................................................... 557
19.8. Tiles .............................................................................................................. 557
Dependencies ................................................................................................ 557
How to integrate Tiles ..................................................................................... 557
UrlBasedViewResolver ............................................................................ 558
ResourceBundleViewResolver ................................................................. 558
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 559
19.9. XSLT ............................................................................................................. 559
My First Words ............................................................................................... 560
Bean definitions ...................................................................................... 560
Standard MVC controller code ................................................................. 560
Document transformation ........................................................................ 561
19.10. Document views (PDF/Excel) ........................................................................ 561
Introduction .................................................................................................... 561
Configuration and setup .................................................................................. 562
Document view definitions ....................................................................... 562
Controller code ....................................................................................... 562
Subclassing for Excel views .................................................................... 562
Subclassing for PDF views ..................................................................... 564
19.11. Feed Views ................................................................................................. 564
19.12. JSON Mapping View .................................................................................... 565
Spring Framework Reference Documentation
5.0.0.BUILD-SNAPSHOT Spring Framework xix
19.13. XML Mapping View ...................................................................................... 565
20. CORS Support ......................................................................................................... 566
20.1. Introduction .................................................................................................... 566
20.2. Controller method CORS configuration ............................................................ 566
20.3. Global CORS configuration ............................................................................. 567
JavaConfig ..................................................................................................... 567
XML namespace ............................................................................................ 568
20.4. Advanced Customization ................................................................................ 568
20.5. Filter based CORS support ............................................................................. 568
21. Integrating with other web frameworks ....................................................................... 570
21.1. Introduction .................................................................................................... 570
21.2. Common configuration ................................................................................... 571
21.3. JavaServer Faces 1.2 .................................................................................... 572
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 572
FacesContextUtils ........................................................................................... 572
21.4. Apache Struts 2.x .......................................................................................... 572
21.5. Tapestry 5.x .................................................................................................. 573
21.6. Further Resources ......................................................................................... 573
22. WebSocket Support .................................................................................................. 574
22.1. Introduction .................................................................................................... 574
WebSocket Fallback Options ........................................................................... 574
A Messaging Architecture ............................................................................... 575
Sub-Protocol Support in WebSocket ................................................................ 575
Should I Use WebSocket? .............................................................................. 575
22.2. WebSocket API ............................................................................................. 576
Create and Configure a WebSocketHandler ..................................................... 576
Customizing the WebSocket Handshake .......................................................... 577
WebSocketHandler Decoration ........................................................................ 578
Deployment Considerations ............................................................................. 578
Configuring the WebSocket Engine ................................................................. 579
Configuring allowed origins ............................................................................. 581
22.3. SockJS Fallback Options ................................................................................ 582
Overview of SockJS ....................................................................................... 582
Enable SockJS ............................................................................................... 583
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 584
Heartbeat Messages ....................................................................................... 585
Servlet 3 Async Requests ............................................................................... 585
CORS Headers for SockJS ............................................................................. 586
SockJS Client ................................................................................................. 586
22.4. STOMP Over WebSocket Messaging Architecture ........................................... 588
Overview of STOMP ....................................................................................... 588
Enable STOMP over WebSocket ..................................................................... 589
Flow of Messages .......................................................................................... 591
Annotation Message Handling ......................................................................... 593
Sending Messages ......................................................................................... 595
Simple Broker ................................................................................................ 595
Full-Featured Broker ....................................................................................... 595
Connections To Full-Featured Broker .............................................................. 596
Using Dot as Separator in @MessageMapping Destinations .............................. 597
Authentication ................................................................................................. 598
Spring Framework Reference Documentation
5.0.0.BUILD-SNAPSHOT Spring Framework xx
User Destinations ........................................................................................... 599
Listening To ApplicationContext Events and Intercepting Messages ................... 600
STOMP Client ................................................................................................ 601
WebSocket Scope .......................................................................................... 603
Configuration and Performance ....................................................................... 604
Runtime Monitoring ......................................................................................... 607
Testing Annotated Controller Methods ............................................................. 608
23. Web Reactive Framework ......................................................................................... 609
23.1. Introduction .................................................................................................... 609
Reactive Programming .................................................................................... 609
Spring Web Reactive Types ............................................................................ 609
23.2. Spring Reactive Web Overview ....................................................................... 609
Spring Web Reactive Module .......................................................................... 609
Reactive Web Client ....................................................................................... 611
23.3. Getting Started .............................................................................................. 611
Spring Boot Starter ......................................................................................... 611
Manual Bootstrapping ..................................................................................... 611
Extent of M1 Support ...................................................................................... 612
VI. Integration ......................................................................................................................... 613
24. Remoting and web services using Spring ................................................................... 614
24.1. Introduction .................................................................................................... 614
24.2. Exposing services using RMI .......................................................................... 615
Exporting the service using the RmiServiceExporter ......................................... 615
Linking in the service at the client ................................................................... 616
24.3. Using Hessian to remotely call services via HTTP ............................................ 616
Wiring up the DispatcherServlet for Hessian and co. ......................................... 616
Exposing your beans by using the HessianServiceExporter ............................... 617
Linking in the service on the client .................................................................. 617
Applying HTTP basic authentication to a service exposed through Hessian ......... 618
24.4. Exposing services using HTTP invokers .......................................................... 618
Exposing the service object ............................................................................ 618
Linking in the service at the client ................................................................... 619
24.5. Web services ................................................................................................. 620
Exposing servlet-based web services using JAX-WS ........................................ 620
Exporting standalone web services using JAX-WS ........................................... 621
Exporting web services using the JAX-WS RI’s Spring support .......................... 621
Accessing web services using JAX-WS ........................................................... 622
24.6. JMS .............................................................................................................. 622
Server-side configuration ................................................................................. 623
Client-side configuration .................................................................................. 624
24.7. AMQP ........................................................................................................... 625
24.8. Auto-detection is not implemented for remote interfaces ................................... 625
24.9. Considerations when choosing a technology .................................................... 625
24.10. Accessing RESTful services on the Client ..................................................... 626
RestTemplate ................................................................................................. 626
Working with the URI .............................................................................. 629
Dealing with request and response headers ............................................. 629
Jackson JSON Views support ................................................................. 630
HTTP Message Conversion ............................................................................ 630
StringHttpMessageConverter ................................................................... 630
剩余854页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2024-09-26 上传
2023-10-10 上传
2008-12-24 上传
2014-10-17 上传
2009-02-12 上传
明天更美好sy
- 粉丝: 2
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 淘淘商城源码-Java代码类资源
- mybatis - Springboot+Mybatis+MySql搭建实例.zip
- 商务团队背景的商务幻灯片下载PPT模板
- Python库 | VizKG-0.0.3-py3-none-any.whl
- 直方图修改:代码执行直方图修改-matlab开发
- Android-project-FishPond:ZJU中的Android课程,这是名为FishPond的最终项目,这是一个适合时间大师的应用
- mm-screen:马克·米纳维尼(Mark Minervini)在“像股票向导一样交易”一书中描述的股票筛选器,用于识别超级绩效股票
- POO-2021
- SergioHPassos.github.io
- Quarantine-Friends:编码Dojo小组项目
- code-red:可视化代码 RED
- EpigenomicsTask_MscOmics
- VK-DMR:VK DMR文件
- kiwi:简约的内存键值存储
- Trex-Game-2:有游戏结束条件
- Python库 | vizex-2.0.4-py3-none-any.whl
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功