没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架4.3.4参考指南
"Spring框架参考文档4.3.4版,PDF格式,英文"
Spring Framework是Java开发中的一个关键工具,由Rod Johnson、Juergen Hoeller等多位开发者共同创建和维护,广泛应用于企业级应用的构建。4.3.4版本的文档详细介绍了该框架的各个组件和功能。
### 1. 概览 (Overview of Spring Framework)
**1.1. 开始使用Spring**
Spring框架的入门通常包括理解其核心概念,如依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)。DI允许开发者通过声明式的方式管理对象之间的依赖关系,而不是硬编码它们。IoC则是一种设计模式,将对象的创建和组装过程交由容器处理,从而使代码更易于测试和维护。
**1.2. Spring框架介绍**
Spring由多个模块组成,每个模块都专注于特定的开发需求:
- **核心容器(Core Container)**:包含Bean工厂(BeanFactory)和ApplicationContext,它们是Spring框架的基础,负责管理应用程序的bean生命周期和配置。
- **面向切面编程(AOP and Instrumentation)**:提供了在运行时修改和增强代码的能力,常用于日志记录、事务管理等跨切面关注点。
- **消息传递(Messaging)**:Spring框架支持消息传递,比如JMS(Java Message Service),使得应用程序可以进行异步通信。
- **数据访问/集成(Data Access/Integration)**:包括对各种数据库的支持,如JDBC、ORM(对象关系映射)框架如Hibernate和MyBatis,以及对NoSQL数据库的支持。
### 2. 详细模块介绍
**2.1. 核心容器(Core Container)**
- **BeanFactory**:它是Spring的核心,负责创建、配置和管理bean。
- **ApplicationContext**:在BeanFactory之上提供更多的企业服务,如国际化、事件传播和AOP代理。
**2.2. 面向切面编程(AOP)**
Spring的AOP模块允许定义方法拦截器和切面,以实现非侵入式的横切关注点。它也支持代理模式,可以创建JDK动态代理或CGLIB代理。
**2.3. 事务管理(Transactions)**
Spring提供了声明式和编程式的事务管理,简化了在多层架构中的事务处理。
**2.4. 数据访问(DataSource)**
Spring提供了与多种数据源的集成,包括JDBC模板、ORM框架集成,以及对JPA、JDO和iBatis的支持。
**2.5. Web模块**
Spring MVC是Spring框架的一部分,用于构建Web应用程序,提供模型-视图-控制器(MVC)架构的支持。
### 3. 其他特性
- **测试(Test)**:Spring提供了一个强大的测试支持框架,包括单元测试和集成测试工具。
- **模块化(Modularity)**:Spring的设计允许开发者根据项目需求选择使用哪些模块,降低了项目的复杂性。
- **安全性(Security)**:Spring Security为应用程序提供了全面的安全管理,包括认证、授权和加密。
Spring Framework 4.3.4版的文档是一个详尽的指南,涵盖了从基础概念到高级特性的各个方面,旨在帮助开发者高效地利用Spring构建健壮、可维护的Java应用程序。无论是新手还是经验丰富的开发者,都能从中受益。
Spring Framework Reference Documentation
4.3.4.RELEASE Spring Framework xvi
XML Schema-based Configuration ........................................................... 470
21.6. Castor ........................................................................................................... 470
CastorMarshaller ............................................................................................ 470
Mapping ......................................................................................................... 471
XML Schema-based Configuration ........................................................... 471
21.7. XMLBeans ..................................................................................................... 472
XmlBeansMarshaller ....................................................................................... 472
XML Schema-based Configuration ........................................................... 472
21.8. JiBX .............................................................................................................. 472
JibxMarshaller ................................................................................................ 473
XML Schema-based Configuration ........................................................... 473
21.9. XStream ........................................................................................................ 473
XStreamMarshaller ......................................................................................... 473
VI. The Web .......................................................................................................................... 475
22. Web MVC framework ................................................................................................ 476
22.1. Introduction to Spring Web MVC framework .................................................... 476
Features of Spring Web MVC ......................................................................... 476
Pluggability of other MVC implementations ...................................................... 478
22.2. The DispatcherServlet .................................................................................... 478
Special Bean Types In the WebApplicationContext ........................................... 482
Default DispatcherServlet Configuration ........................................................... 483
DispatcherServlet Processing Sequence .......................................................... 483
22.3. Implementing Controllers ................................................................................ 485
Defining a controller with @Controller .............................................................. 485
Mapping Requests With @RequestMapping ..................................................... 486
Composed @RequestMapping Variants ................................................... 487
@Controller and AOP Proxying ............................................................... 488
New Support Classes for @RequestMapping methods in Spring MVC 3.1 .. 488
URI Template Patterns ........................................................................... 489
URI Template Patterns with Regular Expressions ..................................... 490
Path Patterns ......................................................................................... 490
Path Pattern Comparison ........................................................................ 491
Path Patterns with Placeholders .............................................................. 491
Suffix Pattern Matching ........................................................................... 491
Suffix Pattern Matching and RFD ............................................................ 491
Matrix Variables ...................................................................................... 492
Consumable Media Types ....................................................................... 494
Producible Media Types .......................................................................... 494
Request Parameters and Header Values ................................................. 495
HTTP HEAD and HTTP OPTIONS .......................................................... 495
Defining @RequestMapping handler methods .................................................. 496
Supported method argument types .......................................................... 496
Supported method return types ............................................................... 498
Binding request parameters to method parameters with @RequestParam ... 499
Mapping the request body with the @RequestBody annotation .................. 500
Mapping the response body with the @ResponseBody annotation ............. 501
Creating REST Controllers with the @RestController annotation ................ 502
Using HttpEntity ...................................................................................... 502
Using @ModelAttribute on a method ....................................................... 502
Using @ModelAttribute on a method argument ......................................... 503
Spring Framework Reference Documentation
4.3.4.RELEASE Spring Framework xvii
Using @SessionAttributes to store model attributes in the HTTP session
between requests ................................................................................... 505
Using @SessionAttribute to access pre-existing global session attributes .... 506
Using @RequestAttribute to access request attributes .............................. 506
Working with "application/x-www-form-urlencoded" data ............................ 506
Mapping cookie values with the @CookieValue annotation ........................ 507
Mapping request header attributes with the @RequestHeader annotation ... 507
Method Parameters And Type Conversion ............................................... 508
Customizing WebDataBinder initialization ................................................. 508
Advising controllers with @ControllerAdvice and @RestControllerAdvice .... 509
Jackson Serialization View Support ......................................................... 510
Jackson JSONP Support ........................................................................ 511
Asynchronous Request Processing .................................................................. 512
Exception Handling for Async Requests ................................................... 513
Intercepting Async Requests ................................................................... 514
HTTP Streaming ..................................................................................... 514
HTTP Streaming With Server-Sent Events ............................................... 514
HTTP Streaming Directly To The OutputStream ....................................... 515
Configuring Asynchronous Request Processing ........................................ 515
Testing Controllers ......................................................................................... 516
22.4. Handler mappings .......................................................................................... 516
Intercepting requests with a HandlerInterceptor ................................................ 517
22.5. Resolving views ............................................................................................. 519
Resolving views with the ViewResolver interface .............................................. 519
Chaining ViewResolvers ................................................................................. 521
Redirecting to Views ....................................................................................... 521
RedirectView .......................................................................................... 522
The redirect: prefix ................................................................................. 523
The forward: prefix ................................................................................. 523
ContentNegotiatingViewResolver ..................................................................... 523
22.6. Using flash attributes ..................................................................................... 525
22.7. Building URIs ................................................................................................. 526
Building URIs to Controllers and methods ........................................................ 527
Building URIs to Controllers and methods from views ....................................... 528
22.8. Using locales ................................................................................................. 529
Obtaining Time Zone Information .................................................................... 529
AcceptHeaderLocaleResolver .......................................................................... 529
CookieLocaleResolver ..................................................................................... 529
SessionLocaleResolver ................................................................................... 530
LocaleChangeInterceptor ................................................................................ 530
22.9. Using themes ................................................................................................ 530
Overview of themes ........................................................................................ 530
Defining themes ............................................................................................. 531
Theme resolvers ............................................................................................. 531
22.10. Spring’s multipart (file upload) support ........................................................... 532
Introduction .................................................................................................... 532
Using a MultipartResolver with Commons FileUpload ........................................ 532
Using a MultipartResolver with Servlet 3.0 ....................................................... 532
Handling a file upload in a form ...................................................................... 533
Handling a file upload request from programmatic clients .................................. 534
Spring Framework Reference Documentation
4.3.4.RELEASE Spring Framework xviii
22.11. Handling exceptions ..................................................................................... 535
HandlerExceptionResolver .............................................................................. 535
@ExceptionHandler ........................................................................................ 535
Handling Standard Spring MVC Exceptions ...................................................... 536
Annotating Business Exceptions With @ResponseStatus .................................. 537
Customizing the Default Servlet Container Error Page ...................................... 537
22.12. Web Security ............................................................................................... 538
22.13. Convention over configuration support ........................................................... 538
The Controller ControllerClassNameHandlerMapping ........................................ 538
The Model ModelMap (ModelAndView) ............................................................ 539
The View - RequestToViewNameTranslator ..................................................... 540
22.14. HTTP caching support .................................................................................. 541
Cache-Control HTTP header ........................................................................... 542
HTTP caching support for static resources ....................................................... 542
Support for the Cache-Control, ETag and Last-Modified response headers in
Controllers ...................................................................................................... 543
Shallow ETag support ..................................................................................... 544
22.15. Code-based Servlet container initialization ..................................................... 545
22.16. Configuring Spring MVC ............................................................................... 546
Enabling the MVC Java Config or the MVC XML Namespace ............................ 547
Customizing the Provided Configuration ........................................................... 548
Conversion and Formatting ............................................................................. 549
Validation ....................................................................................................... 550
Interceptors .................................................................................................... 551
Content Negotiation ........................................................................................ 552
View Controllers ............................................................................................. 553
View Resolvers .............................................................................................. 553
Serving of Resources ..................................................................................... 554
Falling Back On the "Default" Servlet To Serve Resources ................................ 557
Path Matching ................................................................................................ 558
Message Converters ....................................................................................... 559
Advanced Customizations with MVC Java Config ............................................. 560
Advanced Customizations with the MVC Namespace ........................................ 561
23. View technologies ..................................................................................................... 562
23.1. Introduction .................................................................................................... 562
23.2. Thymeleaf ..................................................................................................... 562
23.3. Groovy Markup Templates .............................................................................. 562
Configuration .................................................................................................. 562
Example ......................................................................................................... 563
23.4. Velocity & FreeMarker .................................................................................... 563
Dependencies ................................................................................................ 563
Context configuration ...................................................................................... 563
Creating templates ......................................................................................... 564
Advanced configuration ................................................................................... 564
velocity.properties ................................................................................... 564
FreeMarker ............................................................................................. 565
Bind support and form handling ....................................................................... 565
The bind macros .................................................................................... 565
Simple binding ........................................................................................ 566
Form input generation macros ................................................................. 566
Spring Framework Reference Documentation
4.3.4.RELEASE Spring Framework xix
HTML escaping and XHTML compliance ................................................. 570
23.5. JSP & JSTL .................................................................................................. 570
View resolvers ................................................................................................ 571
'Plain-old' JSPs versus JSTL ........................................................................... 571
Additional tags facilitating development ............................................................ 571
Using Spring’s form tag library ........................................................................ 571
Configuration .......................................................................................... 572
The form tag .......................................................................................... 572
The input tag .......................................................................................... 573
The checkbox tag ................................................................................... 573
The checkboxes tag ............................................................................... 575
The radiobutton tag ................................................................................ 576
The radiobuttons tag ............................................................................... 576
The password tag ................................................................................... 576
The select tag ........................................................................................ 576
The option tag ........................................................................................ 577
The options tag ...................................................................................... 577
The textarea tag ..................................................................................... 578
The hidden tag ....................................................................................... 578
The errors tag ........................................................................................ 578
HTTP Method Conversion ....................................................................... 580
HTML5 Tags .......................................................................................... 581
23.6. Script templates ............................................................................................. 581
Dependencies ................................................................................................ 582
How to integrate script based templating .......................................................... 582
23.7. XML Marshalling View .................................................................................... 584
23.8. Tiles .............................................................................................................. 584
Dependencies ................................................................................................ 584
How to integrate Tiles ..................................................................................... 584
UrlBasedViewResolver ............................................................................ 585
ResourceBundleViewResolver ................................................................. 585
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 586
23.9. XSLT ............................................................................................................. 586
My First Words ............................................................................................... 587
Bean definitions ...................................................................................... 587
Standard MVC controller code ................................................................. 587
Document transformation ........................................................................ 588
23.10. Document views (PDF/Excel) ........................................................................ 588
Introduction .................................................................................................... 588
Configuration and setup .................................................................................. 589
Document view definitions ....................................................................... 589
Controller code ....................................................................................... 589
Subclassing for Excel views .................................................................... 589
Subclassing for PDF views ..................................................................... 591
23.11. JasperReports .............................................................................................. 591
Dependencies ................................................................................................ 591
Configuration .................................................................................................. 591
Configuring the ViewResolver .................................................................. 592
Configuring the Views ............................................................................. 592
About Report Files .................................................................................. 592
Spring Framework Reference Documentation
4.3.4.RELEASE Spring Framework xx
Using JasperReportsMultiFormatView ...................................................... 592
Populating the ModelAndView ......................................................................... 593
Working with Sub-Reports ............................................................................... 594
Configuring Sub-Report Files .................................................................. 594
Configuring Sub-Report Data Sources ..................................................... 595
Configuring Exporter Parameters ..................................................................... 595
23.12. Feed Views ................................................................................................. 596
23.13. JSON Mapping View .................................................................................... 596
23.14. XML Mapping View ...................................................................................... 597
24. Integrating with other web frameworks ....................................................................... 598
24.1. Introduction .................................................................................................... 598
24.2. Common configuration ................................................................................... 599
24.3. JavaServer Faces 1.2 .................................................................................... 600
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 600
FacesContextUtils ........................................................................................... 600
24.4. Apache Struts 2.x .......................................................................................... 600
24.5. Tapestry 5.x .................................................................................................. 601
24.6. Further Resources ......................................................................................... 601
25. Portlet MVC Framework ............................................................................................ 602
25.1. Introduction .................................................................................................... 602
Controllers - The C in MVC ............................................................................ 603
Views - The V in MVC .................................................................................... 603
Web-scoped beans ......................................................................................... 603
25.2. The DispatcherPortlet ..................................................................................... 603
25.3. The ViewRendererServlet ............................................................................... 605
25.4. Controllers ..................................................................................................... 606
AbstractController and PortletContentGenerator ............................................... 607
Other simple controllers .................................................................................. 608
Command Controllers ..................................................................................... 608
PortletWrappingController ................................................................................ 609
25.5. Handler mappings .......................................................................................... 609
PortletModeHandlerMapping ............................................................................ 610
ParameterHandlerMapping .............................................................................. 610
PortletModeParameterHandlerMapping ............................................................ 611
Adding HandlerInterceptors ............................................................................. 611
HandlerInterceptorAdapter ............................................................................... 612
ParameterMappingInterceptor .......................................................................... 612
25.6. Views and resolving them .............................................................................. 612
25.7. Multipart (file upload) support ......................................................................... 612
Using the PortletMultipartResolver ................................................................... 613
Handling a file upload in a form ...................................................................... 613
25.8. Handling exceptions ....................................................................................... 617
25.9. Annotation-based controller configuration ........................................................ 617
Setting up the dispatcher for annotation support ............................................... 617
Defining a controller with @Controller .............................................................. 618
Mapping requests with @RequestMapping ....................................................... 618
Supported handler method arguments ............................................................. 620
Binding request parameters to method parameters with @RequestParam .......... 622
Providing a link to data from the model with @ModelAttribute ............................ 622
Specifying attributes to store in a Session with @SessionAttributes .................... 623
剩余909页未读,继续阅读
2016-12-14 上传
2020-12-03 上传
2017-01-09 上传
2017-03-07 上传
2016-12-20 上传
2017-08-11 上传
2017-01-09 上传
BugereguB
- 粉丝: 36
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- JavaScript实现的高效pomodoro时钟教程
- CMake 3.25.3版本发布:程序员必备构建工具
- 直流无刷电机控制技术项目源码集合
- Ak Kamal电子安全客户端加载器-CRX插件介绍
- 揭露流氓软件:月息背后的秘密
- 京东自动抢购茅台脚本指南:如何设置eid与fp参数
- 动态格式化Matlab轴刻度标签 - ticklabelformat实用教程
- DSTUHack2021后端接口与Go语言实现解析
- CMake 3.25.2版本Linux软件包发布
- Node.js网络数据抓取技术深入解析
- QRSorteios-crx扩展:优化税务文件扫描流程
- 掌握JavaScript中的算法技巧
- Rails+React打造MF员工租房解决方案
- Utsanjan:自学成才的UI/UX设计师与技术博客作者
- CMake 3.25.2版本发布,支持Windows x86_64架构
- AR_RENTAL平台:HTML技术在增强现实领域的应用
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功