没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring 4.0 官方指南:依赖注入与模块详解
Spring 4.0 官方参考手册是Spring框架的权威文档,由多位经验丰富的开发者共同编写,包括Rod Johnson、Juergen Hoeller等人。该文档适用于4.3.9版本,涵盖了Spring Framework的核心概念和技术细节,旨在帮助开发人员深入理解并掌握这个强大的轻量级Java框架。
1. **概述与入门**:
首章提供了一个Spring Framework的全面概览,让读者快速了解其基本原理。章节中会介绍如何通过Spring的依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)原则来组织和管理应用组件,这两个核心机制在Spring中扮演着至关重要的角色。
2. **Spring模块**:
文档详细介绍了Spring的各个模块,如核心容器(Core Container),它负责应用程序的生命周期管理和组件装配。此外,还涵盖了面向切面编程(Aspect Oriented Programming, AOP)和性能监控(Instrumentation)等高级特性,这些对于实现复杂业务逻辑和代码优化至关重要。
3. **核心组件**:
紧接着是对Spring容器的深入剖析,阐述了如何利用容器创建和管理对象实例,以及配置Bean的生命周期和依赖关系。这对于理解Spring的运行机制以及如何编写配置文件十分关键。
4. **AOP和自动代理**:
AOP部分讲解了如何利用Spring的代理机制实现代码的横切关注点(如日志、事务管理等),并通过声明式编程方式实现代码的解耦。
5. **消息传递**:
没有提到具体的“消息传递”部分,但可以推测这部分可能涉及Spring的通信和集成能力,如消息队列、WebSocket或者JMS支持,这些功能在现代微服务架构中不可或缺。
6. **版权与使用许可**:
显示文档允许用户出于个人学习和非商业目的复制,并确保每个副本包含版权声明,无论以纸质还是电子形式分发。
通过阅读Spring 4.0 官方参考手册,开发人员能够获得一个坚实的基础,用于构建高效、可扩展和可维护的Java应用程序。无论是初学者还是经验丰富的开发者,都可以从中受益匪浅,不断深化对Spring框架的理解和实践能力。
![](https://csdnimg.cn/release/download_crawler_static/9867831/bg10.jpg)
Spring Framework Reference Documentation
4.3.9.RELEASE Spring Framework xvi
21.3. Using Marshaller and Unmarshaller ................................................................. 469
21.4. XML Schema-based Configuration .................................................................. 471
21.5. JAXB ............................................................................................................. 471
Jaxb2Marshaller ............................................................................................. 471
XML Schema-based Configuration ........................................................... 472
21.6. Castor ........................................................................................................... 472
CastorMarshaller ............................................................................................ 472
Mapping ......................................................................................................... 473
XML Schema-based Configuration ........................................................... 473
21.7. XMLBeans ..................................................................................................... 474
XmlBeansMarshaller ....................................................................................... 474
XML Schema-based Configuration ........................................................... 474
21.8. JiBX .............................................................................................................. 474
JibxMarshaller ................................................................................................ 475
XML Schema-based Configuration ........................................................... 475
21.9. XStream ........................................................................................................ 475
XStreamMarshaller ......................................................................................... 475
VI. The Web .......................................................................................................................... 477
22. Web MVC framework ................................................................................................ 478
22.1. Introduction to Spring Web MVC framework .................................................... 478
Features of Spring Web MVC ......................................................................... 478
Pluggability of other MVC implementations ...................................................... 480
22.2. The DispatcherServlet .................................................................................... 480
Special Bean Types In the WebApplicationContext ........................................... 484
Default DispatcherServlet Configuration ........................................................... 485
DispatcherServlet Processing Sequence .......................................................... 485
22.3. Implementing Controllers ................................................................................ 487
Defining a controller with @Controller .............................................................. 487
Mapping Requests With @RequestMapping ..................................................... 488
Composed @RequestMapping Variants ................................................... 489
@Controller and AOP Proxying ............................................................... 490
New Support Classes for @RequestMapping methods in Spring MVC 3.1 .. 490
URI Template Patterns ........................................................................... 491
URI Template Patterns with Regular Expressions ..................................... 492
Path Patterns ......................................................................................... 492
Path Pattern Comparison ........................................................................ 493
Path Patterns with Placeholders .............................................................. 493
Suffix Pattern Matching ........................................................................... 493
Suffix Pattern Matching and RFD ............................................................ 493
Matrix Variables ...................................................................................... 494
Consumable Media Types ....................................................................... 496
Producible Media Types .......................................................................... 496
Request Parameters and Header Values ................................................. 497
HTTP HEAD and HTTP OPTIONS .......................................................... 497
Defining @RequestMapping handler methods .................................................. 498
Supported method argument types .......................................................... 498
Supported method return types ............................................................... 500
Binding request parameters to method parameters with @RequestParam ... 501
Mapping the request body with the @RequestBody annotation .................. 502
Mapping the response body with the @ResponseBody annotation ............. 503
![](https://csdnimg.cn/release/download_crawler_static/9867831/bg11.jpg)
Spring Framework Reference Documentation
4.3.9.RELEASE Spring Framework xvii
Creating REST Controllers with the @RestController annotation ................ 504
Using HttpEntity ...................................................................................... 504
Using @ModelAttribute on a method ....................................................... 504
Using @ModelAttribute on a method argument ......................................... 505
Using @SessionAttributes to store model attributes in the HTTP session
between requests ................................................................................... 507
Using @SessionAttribute to access pre-existing global session attributes .... 508
Using @RequestAttribute to access request attributes .............................. 508
Working with "application/x-www-form-urlencoded" data ............................ 508
Mapping cookie values with the @CookieValue annotation ........................ 509
Mapping request header attributes with the @RequestHeader annotation ... 509
Method Parameters And Type Conversion ............................................... 510
Customizing WebDataBinder initialization ................................................. 510
Advising controllers with @ControllerAdvice and @RestControllerAdvice .... 511
Jackson Serialization View Support ......................................................... 512
Jackson JSONP Support ........................................................................ 513
Asynchronous Request Processing .................................................................. 514
Exception Handling for Async Requests ................................................... 515
Intercepting Async Requests ................................................................... 516
HTTP Streaming ..................................................................................... 516
HTTP Streaming With Server-Sent Events ............................................... 516
HTTP Streaming Directly To The OutputStream ....................................... 517
Configuring Asynchronous Request Processing ........................................ 517
Testing Controllers ......................................................................................... 518
22.4. Handler mappings .......................................................................................... 518
Intercepting requests with a HandlerInterceptor ................................................ 519
22.5. Resolving views ............................................................................................. 521
Resolving views with the ViewResolver interface .............................................. 521
Chaining ViewResolvers ................................................................................. 523
Redirecting to Views ....................................................................................... 523
RedirectView .......................................................................................... 524
The redirect: prefix ................................................................................. 525
The forward: prefix ................................................................................. 525
ContentNegotiatingViewResolver ..................................................................... 525
22.6. Using flash attributes ..................................................................................... 527
22.7. Building URIs ................................................................................................. 528
Building URIs to Controllers and methods ........................................................ 529
Working with "Forwarded" and "X-Forwarded-*" Headers .................................. 530
Building URIs to Controllers and methods from views ....................................... 530
22.8. Using locales ................................................................................................. 531
Obtaining Time Zone Information .................................................................... 531
AcceptHeaderLocaleResolver .......................................................................... 532
CookieLocaleResolver ..................................................................................... 532
SessionLocaleResolver ................................................................................... 532
LocaleChangeInterceptor ................................................................................ 532
22.9. Using themes ................................................................................................ 533
Overview of themes ........................................................................................ 533
Defining themes ............................................................................................. 533
Theme resolvers ............................................................................................. 534
22.10. Spring’s multipart (file upload) support ........................................................... 534
![](https://csdnimg.cn/release/download_crawler_static/9867831/bg12.jpg)
Spring Framework Reference Documentation
4.3.9.RELEASE Spring Framework xviii
Introduction .................................................................................................... 534
Using a MultipartResolver with Commons FileUpload ........................................ 534
Using a MultipartResolver with Servlet 3.0 ....................................................... 535
Handling a file upload in a form ...................................................................... 535
Handling a file upload request from programmatic clients .................................. 536
22.11. Handling exceptions ..................................................................................... 537
HandlerExceptionResolver .............................................................................. 537
@ExceptionHandler ........................................................................................ 537
Handling Standard Spring MVC Exceptions ...................................................... 538
Annotating Business Exceptions With @ResponseStatus .................................. 539
Customizing the Default Servlet Container Error Page ...................................... 539
22.12. Web Security ............................................................................................... 540
22.13. Convention over configuration support ........................................................... 540
The Controller ControllerClassNameHandlerMapping ........................................ 540
The Model ModelMap (ModelAndView) ............................................................ 541
The View - RequestToViewNameTranslator ..................................................... 543
22.14. HTTP caching support .................................................................................. 544
Cache-Control HTTP header ........................................................................... 544
HTTP caching support for static resources ....................................................... 545
Support for the Cache-Control, ETag and Last-Modified response headers in
Controllers ...................................................................................................... 545
Shallow ETag support ..................................................................................... 546
22.15. Code-based Servlet container initialization ..................................................... 547
22.16. Configuring Spring MVC ............................................................................... 549
Enabling the MVC Java Config or the MVC XML Namespace ............................ 549
Customizing the Provided Configuration ........................................................... 551
Conversion and Formatting ............................................................................. 551
Validation ....................................................................................................... 552
Interceptors .................................................................................................... 553
Content Negotiation ........................................................................................ 554
View Controllers ............................................................................................. 555
View Resolvers .............................................................................................. 555
Serving of Resources ..................................................................................... 556
Falling Back On the "Default" Servlet To Serve Resources ................................ 559
Path Matching ................................................................................................ 560
Message Converters ....................................................................................... 561
Advanced Customizations with MVC Java Config ............................................. 562
Advanced Customizations with the MVC Namespace ........................................ 563
23. View technologies ..................................................................................................... 564
23.1. Introduction .................................................................................................... 564
23.2. Thymeleaf ..................................................................................................... 564
23.3. Groovy Markup Templates .............................................................................. 564
Configuration .................................................................................................. 564
Example ......................................................................................................... 565
23.4. Velocity & FreeMarker .................................................................................... 565
Dependencies ................................................................................................ 565
Context configuration ...................................................................................... 565
Creating templates ......................................................................................... 566
Advanced configuration ................................................................................... 566
velocity.properties ................................................................................... 566
![](https://csdnimg.cn/release/download_crawler_static/9867831/bg13.jpg)
Spring Framework Reference Documentation
4.3.9.RELEASE Spring Framework xix
FreeMarker ............................................................................................. 567
Bind support and form handling ....................................................................... 567
The bind macros .................................................................................... 567
Simple binding ........................................................................................ 568
Form input generation macros ................................................................. 568
HTML escaping and XHTML compliance ................................................. 572
23.5. JSP & JSTL .................................................................................................. 572
View resolvers ................................................................................................ 573
'Plain-old' JSPs versus JSTL ........................................................................... 573
Additional tags facilitating development ............................................................ 573
Using Spring’s form tag library ........................................................................ 573
Configuration .......................................................................................... 574
The form tag .......................................................................................... 574
The input tag .......................................................................................... 575
The checkbox tag ................................................................................... 575
The checkboxes tag ............................................................................... 577
The radiobutton tag ................................................................................ 578
The radiobuttons tag ............................................................................... 578
The password tag ................................................................................... 578
The select tag ........................................................................................ 578
The option tag ........................................................................................ 579
The options tag ...................................................................................... 579
The textarea tag ..................................................................................... 580
The hidden tag ....................................................................................... 580
The errors tag ........................................................................................ 580
HTTP Method Conversion ....................................................................... 582
HTML5 Tags .......................................................................................... 583
23.6. Script templates ............................................................................................. 583
Dependencies ................................................................................................ 584
How to integrate script based templating .......................................................... 584
23.7. XML Marshalling View .................................................................................... 586
23.8. Tiles .............................................................................................................. 586
Dependencies ................................................................................................ 586
How to integrate Tiles ..................................................................................... 586
UrlBasedViewResolver ............................................................................ 587
ResourceBundleViewResolver ................................................................. 587
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 588
23.9. XSLT ............................................................................................................. 588
My First Words ............................................................................................... 589
Bean definitions ...................................................................................... 589
Standard MVC controller code ................................................................. 589
Document transformation ........................................................................ 590
23.10. Document views (PDF/Excel) ........................................................................ 590
Introduction .................................................................................................... 590
Configuration and setup .................................................................................. 591
Document view definitions ....................................................................... 591
Controller code ....................................................................................... 591
Subclassing for Excel views .................................................................... 591
Subclassing for PDF views ..................................................................... 593
23.11. JasperReports .............................................................................................. 593
![](https://csdnimg.cn/release/download_crawler_static/9867831/bg14.jpg)
Spring Framework Reference Documentation
4.3.9.RELEASE Spring Framework xx
Dependencies ................................................................................................ 593
Configuration .................................................................................................. 593
Configuring the ViewResolver .................................................................. 594
Configuring the Views ............................................................................. 594
About Report Files .................................................................................. 594
Using JasperReportsMultiFormatView ...................................................... 594
Populating the ModelAndView ......................................................................... 595
Working with Sub-Reports ............................................................................... 596
Configuring Sub-Report Files .................................................................. 596
Configuring Sub-Report Data Sources ..................................................... 597
Configuring Exporter Parameters ..................................................................... 597
23.12. Feed Views ................................................................................................. 598
23.13. JSON Mapping View .................................................................................... 598
23.14. XML Mapping View ...................................................................................... 599
24. Integrating with other web frameworks ....................................................................... 600
24.1. Introduction .................................................................................................... 600
24.2. Common configuration ................................................................................... 601
24.3. JavaServer Faces 1.2 .................................................................................... 602
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 602
FacesContextUtils ........................................................................................... 602
24.4. Apache Struts 2.x .......................................................................................... 602
24.5. Tapestry 5.x .................................................................................................. 603
24.6. Further Resources ......................................................................................... 603
25. Portlet MVC Framework ............................................................................................ 604
25.1. Introduction .................................................................................................... 604
Controllers - The C in MVC ............................................................................ 605
Views - The V in MVC .................................................................................... 605
Web-scoped beans ......................................................................................... 605
25.2. The DispatcherPortlet ..................................................................................... 605
25.3. The ViewRendererServlet ............................................................................... 607
25.4. Controllers ..................................................................................................... 608
AbstractController and PortletContentGenerator ............................................... 609
Other simple controllers .................................................................................. 610
Command Controllers ..................................................................................... 610
PortletWrappingController ................................................................................ 611
25.5. Handler mappings .......................................................................................... 611
PortletModeHandlerMapping ............................................................................ 612
ParameterHandlerMapping .............................................................................. 612
PortletModeParameterHandlerMapping ............................................................ 613
Adding HandlerInterceptors ............................................................................. 613
HandlerInterceptorAdapter ............................................................................... 614
ParameterMappingInterceptor .......................................................................... 614
25.6. Views and resolving them .............................................................................. 614
25.7. Multipart (file upload) support ......................................................................... 614
Using the PortletMultipartResolver ................................................................... 615
Handling a file upload in a form ...................................................................... 615
25.8. Handling exceptions ....................................................................................... 619
25.9. Annotation-based controller configuration ........................................................ 619
Setting up the dispatcher for annotation support ............................................... 619
Defining a controller with @Controller .............................................................. 620
剩余912页未读,继续阅读
2019-06-10 上传
2023-06-10 上传
2023-10-25 上传
2023-03-16 上传
2023-06-28 上传
2024-04-28 上传
2023-08-04 上传
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
britney2spears
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 计算机人脸表情动画技术发展综述
- 关系数据库的关键字搜索技术综述:模型、架构与未来趋势
- 迭代自适应逆滤波在语音情感识别中的应用
- 概念知识树在旅游领域智能分析中的应用
- 构建is-a层次与OWL本体集成:理论与算法
- 基于语义元的相似度计算方法研究:改进与有效性验证
- 网格梯度多密度聚类算法:去噪与高效聚类
- 网格服务工作流动态调度算法PGSWA研究
- 突发事件连锁反应网络模型与应急预警分析
- BA网络上的病毒营销与网站推广仿真研究
- 离散HSMM故障预测模型:有效提升系统状态预测
- 煤矿安全评价:信息融合与可拓理论的应用
- 多维度Petri网工作流模型MD_WFN:统一建模与应用研究
- 面向过程追踪的知识安全描述方法
- 基于收益的软件过程资源调度优化策略
- 多核环境下基于数据流Java的Web服务器优化实现提升性能
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)