没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring Framework 4官方文档(4.1.0.RELEASE)详解
Spring Framework 4官方文档(4.1.0.RELEASE)详解
需积分: 10 22 下载量 165 浏览量
更新于2024-07-23
收藏 4.9MB PDF 举报
Spring Framework 4 是一款强大的开源企业级应用开发框架,它由 Rod Johnson、Juergen Hoeller、Keith Donald 等众多开发者共同贡献,自2004年成立以来,历经多次迭代更新。该文档是Spring Framework 4.1.0.RELEASE的官方参考手册,提供了全面的技术细节和指导。
1. **概述与入门**:
开篇部分介绍了Spring框架的整体概念,包括如何通过Spring快速入门,使开发人员能够利用其依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)的设计模式。Spring的核心目标是简化企业级应用的开发,通过模块化设计,如核心容器(Core Container)、面向切面编程(AOP)和性能监控,使得代码更易于管理。
2. **核心组件**:
- **核心容器**:这是Spring框架的核心部分,它负责创建和管理对象实例,实现DI和IoC,帮助开发者将关注点从具体的对象创建和管理转移到业务逻辑上。
- **AOP和Instrumentation**:AOP允许在不改变原有代码的情况下,增加额外的行为或进行性能监控,通过Spring的代理机制实现代码的透明性。Instrumentation则涉及程序的性能分析和调优。
3. **消息传递**:
Spring框架提供了对多种消息传递机制的支持,包括异步通信和事件驱动编程,有助于构建可扩展和响应式的系统架构。
4. **数据访问**:
文档详细解释了Spring如何与数据库交互,包括JDBC、ORM(如Hibernate和MyBatis)以及集成NoSQL技术的适配。Spring Data是一大亮点,它简化了数据访问操作,并提供了一致的API接口。
5. **其他功能**:
- 它还包括了Spring MVC用于构建Web应用程序的模型-视图-控制器架构,Spring Security用于安全管理,以及Spring Boot快速启动工具,使得开发人员能够更快地构建和部署应用。
版权信息表明,用户可以根据需要制作副本,但必须确保不收取费用,并且每个副本都包含版权声明,无论是打印还是电子形式分发。
Spring Framework 4 是一个高度模块化且功能丰富的开发平台,它通过先进的设计原则和API,简化了企业级应用的开发过程,提高代码质量和可维护性。这份文档为开发人员提供了深入理解和实践Spring框架的宝贵资源。
Spring Framework Reference Documentation
4.1.0.RELEASE Spring Framework xvi
17.10. Spring’s multipart (file upload) support ........................................................... 485
Introduction .................................................................................................... 485
Using a MultipartResolver with Commons FileUpload ........................................ 485
Using a MultipartResolver with Servlet 3.0 ....................................................... 486
Handling a file upload in a form ...................................................................... 486
Handling a file upload request from programmatic clients .................................. 487
17.11. Handling exceptions ..................................................................................... 488
HandlerExceptionResolver .............................................................................. 488
@ExceptionHandler ........................................................................................ 488
Handling Standard Spring MVC Exceptions ...................................................... 489
Annotating Business Exceptions With @ResponseStatus .................................. 490
Customizing the Default Servlet Container Error Page ...................................... 490
17.12. Web Security ............................................................................................... 491
17.13. Convention over configuration support ........................................................... 491
The Controller ControllerClassNameHandlerMapping ........................................ 491
The Model ModelMap (ModelAndView) ............................................................ 492
The View - RequestToViewNameTranslator ..................................................... 494
17.14. ETag support ............................................................................................... 495
17.15. Code-based Servlet container initialization ..................................................... 495
17.16. Configuring Spring MVC ............................................................................... 497
Enabling the MVC Java Config or the MVC XML Namespace ............................ 497
Customizing the Provided Configuration ........................................................... 499
Interceptors .................................................................................................... 499
Content Negotiation ........................................................................................ 500
View Controllers ............................................................................................. 501
View Resolvers .............................................................................................. 501
Serving of Resources ..................................................................................... 503
Falling Back On the "Default" Servlet To Serve Resources ................................ 505
Path Matching ................................................................................................ 506
Advanced Customizations with MVC Java Config ............................................. 506
Advanced Customizations with the MVC Namespace ........................................ 507
18. View technologies ..................................................................................................... 508
18.1. Introduction .................................................................................................... 508
18.2. JSP & JSTL .................................................................................................. 508
View resolvers ................................................................................................ 508
Plain-old JSPs versus JSTL ............................................................................ 509
Additional tags facilitating development ............................................................ 509
Using Spring’s form tag library ........................................................................ 509
Configuration .......................................................................................... 509
The form tag .......................................................................................... 509
The input tag .......................................................................................... 511
The checkbox tag ................................................................................... 511
The checkboxes tag ............................................................................... 513
The radiobutton tag ................................................................................ 513
The radiobuttons tag ............................................................................... 513
The password tag ................................................................................... 514
The select tag ........................................................................................ 514
The option tag ........................................................................................ 514
The options tag ...................................................................................... 515
The textarea tag ..................................................................................... 516
Spring Framework Reference Documentation
4.1.0.RELEASE Spring Framework xvii
The hidden tag ....................................................................................... 516
The errors tag ........................................................................................ 516
HTTP Method Conversion ....................................................................... 518
HTML5 Tags .......................................................................................... 519
18.3. Tiles .............................................................................................................. 519
Dependencies ................................................................................................ 519
How to integrate Tiles ..................................................................................... 519
UrlBasedViewResolver ............................................................................ 520
ResourceBundleViewResolver ................................................................. 520
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 521
18.4. Velocity & FreeMarker .................................................................................... 521
Dependencies ................................................................................................ 522
Context configuration ...................................................................................... 522
Creating templates ......................................................................................... 522
Advanced configuration ................................................................................... 523
velocity.properties ................................................................................... 523
FreeMarker ............................................................................................. 523
Bind support and form handling ....................................................................... 524
The bind macros .................................................................................... 524
Simple binding ........................................................................................ 524
Form input generation macros ................................................................. 525
HTML escaping and XHTML compliance ................................................. 528
18.5. XSLT ............................................................................................................. 529
My First Words ............................................................................................... 529
Bean definitions ...................................................................................... 529
Standard MVC controller code ................................................................. 529
Convert the model data to XML ............................................................... 530
Defining the view properties .................................................................... 530
Document transformation ........................................................................ 531
Summary ....................................................................................................... 531
18.6. Document views (PDF/Excel) .......................................................................... 532
Introduction .................................................................................................... 532
Configuration and setup .................................................................................. 532
Document view definitions ....................................................................... 532
Controller code ....................................................................................... 532
Subclassing for Excel views .................................................................... 532
Subclassing for PDF views ..................................................................... 534
18.7. JasperReports ............................................................................................... 534
Dependencies ................................................................................................ 534
Configuration .................................................................................................. 534
Configuring the ViewResolver .................................................................. 535
Configuring the Views ............................................................................. 535
About Report Files .................................................................................. 535
Using JasperReportsMultiFormatView ...................................................... 535
Populating the ModelAndView ......................................................................... 536
Working with Sub-Reports ............................................................................... 537
Configuring Sub-Report Files .................................................................. 537
Configuring Sub-Report Data Sources ..................................................... 538
Configuring Exporter Parameters ..................................................................... 538
18.8. Feed Views ................................................................................................... 539
Spring Framework Reference Documentation
4.1.0.RELEASE Spring Framework xviii
18.9. XML Marshalling View .................................................................................... 539
18.10. JSON Mapping View .................................................................................... 540
18.11. XML Mapping View ...................................................................................... 540
19. Integrating with other web frameworks ....................................................................... 541
19.1. Introduction .................................................................................................... 541
19.2. Common configuration ................................................................................... 542
19.3. JavaServer Faces 1.2 .................................................................................... 543
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 543
FacesContextUtils ........................................................................................... 543
19.4. Apache Struts 2.x .......................................................................................... 543
19.5. Tapestry 5.x .................................................................................................. 544
19.6. Further Resources ......................................................................................... 544
20. Portlet MVC Framework ............................................................................................ 545
20.1. Introduction .................................................................................................... 545
Controllers - The C in MVC ............................................................................ 546
Views - The V in MVC .................................................................................... 546
Web-scoped beans ......................................................................................... 546
20.2. The DispatcherPortlet ..................................................................................... 546
20.3. The ViewRendererServlet ............................................................................... 548
20.4. Controllers ..................................................................................................... 549
AbstractController and PortletContentGenerator ............................................... 550
Other simple controllers .................................................................................. 551
Command Controllers ..................................................................................... 551
PortletWrappingController ................................................................................ 552
20.5. Handler mappings .......................................................................................... 552
PortletModeHandlerMapping ............................................................................ 553
ParameterHandlerMapping .............................................................................. 553
PortletModeParameterHandlerMapping ............................................................ 554
Adding HandlerInterceptors ............................................................................. 554
HandlerInterceptorAdapter ............................................................................... 555
ParameterMappingInterceptor .......................................................................... 555
20.6. Views and resolving them .............................................................................. 555
20.7. Multipart (file upload) support ......................................................................... 555
Using the PortletMultipartResolver ................................................................... 556
Handling a file upload in a form ...................................................................... 556
20.8. Handling exceptions ....................................................................................... 560
20.9. Annotation-based controller configuration ........................................................ 560
Setting up the dispatcher for annotation support ............................................... 560
Defining a controller with @Controller .............................................................. 561
Mapping requests with @RequestMapping ....................................................... 561
Supported handler method arguments ............................................................. 563
Binding request parameters to method parameters with @RequestParam .......... 564
Providing a link to data from the model with @ModelAttribute ............................ 564
Specifying attributes to store in a Session with @SessionAttributes .................... 565
Customizing WebDataBinder initialization ......................................................... 565
Customizing data binding with @InitBinder ............................................... 566
Configuring a custom WebBindingInitializer .............................................. 566
20.10. Portlet application deployment ...................................................................... 566
21. WebSocket Support .................................................................................................. 568
21.1. Introduction .................................................................................................... 568
Spring Framework Reference Documentation
4.1.0.RELEASE Spring Framework xix
WebSocket Fallback Options ........................................................................... 568
A Messaging Architecture ............................................................................... 569
Sub-Protocol Support in WebSocket ................................................................ 569
Should I Use WebSocket? .............................................................................. 569
21.2. WebSocket API ............................................................................................. 570
Create and Configure a WebSocketHandler ..................................................... 570
Customizing the WebSocket Handshake .......................................................... 571
WebSocketHandler Decoration ........................................................................ 572
Deployment Considerations ............................................................................. 572
Configuring the WebSocket Engine ................................................................. 573
21.3. SockJS Fallback Options ................................................................................ 575
Overview of SockJS ....................................................................................... 575
Enable SockJS ............................................................................................... 576
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 577
Heartbeat Messages ....................................................................................... 578
Servlet 3 Async Requests ............................................................................... 578
CORS Headers for SockJS ............................................................................. 579
SockJS Client ................................................................................................. 579
21.4. STOMP Over WebSocket Messaging Architecture ........................................... 580
Overview of STOMP ....................................................................................... 581
Enable STOMP over WebSocket ..................................................................... 582
Flow of Messages .......................................................................................... 583
Annotation Message Handling ......................................................................... 585
Sending Messages ......................................................................................... 586
Simple Broker ................................................................................................ 586
Full-Featured Broker ....................................................................................... 586
Connections To Full-Featured Broker .............................................................. 588
Using Dot as Separator in @MessageMapping Destinations ............................. 588
Authentication ................................................................................................. 589
User Destinations ........................................................................................... 590
Listening To ApplicationContext Events and Intercepting Messages ................... 591
WebSocket Scope .......................................................................................... 593
Configuration and Performance ....................................................................... 594
Runtime Monitoring ......................................................................................... 596
Testing Annotated Controller Methods ............................................................. 597
VI. Integration ......................................................................................................................... 599
22. Remoting and web services using Spring ................................................................... 600
22.1. Introduction .................................................................................................... 600
22.2. Exposing services using RMI .......................................................................... 601
Exporting the service using the RmiServiceExporter ......................................... 601
Linking in the service at the client ................................................................... 602
22.3. Using Hessian or Burlap to remotely call services via HTTP .............................. 602
Wiring up the DispatcherServlet for Hessian and co. ......................................... 602
Exposing your beans by using the HessianServiceExporter ............................... 603
Linking in the service on the client .................................................................. 603
Using Burlap .................................................................................................. 604
Applying HTTP basic authentication to a service exposed through Hessian or
Burlap ............................................................................................................ 604
22.4. Exposing services using HTTP invokers .......................................................... 604
Exposing the service object ............................................................................ 605
Spring Framework Reference Documentation
4.1.0.RELEASE Spring Framework xx
Linking in the service at the client ................................................................... 606
22.5. Web services ................................................................................................. 606
Exposing servlet-based web services using JAX-WS ........................................ 606
Exporting standalone web services using JAX-WS ........................................... 607
Exporting web services using the JAX-WS RI’s Spring support .......................... 608
Accessing web services using JAX-WS ........................................................... 608
22.6. JMS .............................................................................................................. 609
Server-side configuration ................................................................................. 610
Client-side configuration .................................................................................. 610
22.7. AMQP ........................................................................................................... 611
22.8. Auto-detection is not implemented for remote interfaces ................................... 611
22.9. Considerations when choosing a technology .................................................... 612
22.10. Accessing RESTful services on the Client ..................................................... 612
RestTemplate ................................................................................................. 612
Working with the URI .............................................................................. 615
Dealing with request and response headers ............................................. 616
Jackson JSON Views support ................................................................. 616
HTTP Message Conversion ............................................................................ 616
StringHttpMessageConverter ................................................................... 617
FormHttpMessageConverter .................................................................... 617
ByteArrayHttpMessageConverter ............................................................. 617
MarshallingHttpMessageConverter ........................................................... 617
MappingJackson2HttpMessageConverter ................................................. 617
MappingJackson2XmlHttpMessageConverter ........................................... 618
SourceHttpMessageConverter ................................................................. 618
BufferedImageHttpMessageConverter ...................................................... 618
Async RestTemplate ....................................................................................... 618
23. Enterprise JavaBeans (EJB) integration ..................................................................... 620
23.1. Introduction .................................................................................................... 620
23.2. Accessing EJBs ............................................................................................. 620
Concepts ........................................................................................................ 620
Accessing local SLSBs ................................................................................... 620
Accessing remote SLSBs ................................................................................ 622
Accessing EJB 2.x SLSBs versus EJB 3 SLSBs ............................................... 622
23.3. Using Spring’s EJB implementation support classes ......................................... 623
EJB 3 injection interceptor .............................................................................. 623
24. JMS (Java Message Service) .................................................................................... 624
24.1. Introduction .................................................................................................... 624
24.2. Using Spring JMS .......................................................................................... 624
JmsTemplate .................................................................................................. 624
Connections ................................................................................................... 625
Caching Messaging Resources ............................................................... 625
SingleConnectionFactory ......................................................................... 626
CachingConnectionFactory ...................................................................... 626
Destination Management ................................................................................. 626
Message Listener Containers .......................................................................... 627
SimpleMessageListenerContainer ............................................................ 627
DefaultMessageListenerContainer ............................................................ 627
Transaction management ................................................................................ 628
24.3. Sending a Message ....................................................................................... 628
剩余839页未读,继续阅读
点击了解资源详情
166 浏览量
点击了解资源详情
127 浏览量
2018-05-10 上传
592 浏览量
195 浏览量
545 浏览量
545 浏览量
ZHXfaith1121
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功