没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring Framework 4.3.22.RELEASE官方参考指南
Spring Framework 4.3.22.RELEASE官方参考指南
需积分: 6 0 下载量 128 浏览量
更新于2024-07-17
收藏 5.52MB PDF 举报
"Spring Framework Reference 4.pdf 是一份英文的 Spring Framework 指南文档,涵盖了多个版本号,这里提到的是 4.3.22.RELEASE。这份文档由 Rod Johnson、Juergen Hoeller 等多位核心贡献者编写,版权归属 2004-2016 年的作者们。文档可以自由复制和分发,但不得收费。"
Spring Framework 是一个开源的应用程序框架,主要用于构建 Java 应用,特别是企业级应用。它提供了一个全面的编程和配置模型,旨在简化开发过程并促进良好的编程实践。以下是文档中涉及的一些关键知识点:
1. **依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)**:这是 Spring Framework 的核心特性之一。DI 允许开发者解耦组件,使得应用程序的各个部分可以在不关心彼此的具体实现的情况下进行协作。IoC 容器(如 Spring 的 ApplicationContext 或 BeanFactory)负责管理对象的生命周期和依赖关系。
2. **核心容器(Core Container)**:包括了 Beans 模块和 Core 模块,主要负责 Bean 的定义、配置、初始化和管理。Bean 是 Spring 中的基本组成单元,可以是任何 Java 对象,Spring 通过 XML、注解或 Java 配置来管理它们。
3. **面向切面编程(Aspect-Oriented Programming, AOP)和 instrumentation**:AOP 提供了一种模块化横切关注点(如日志、事务管理)的方式,使得代码更加清晰和可维护。Instrumentation 主要用于类加载器级别的操作,如代理生成和内存分析工具的支持。
4. **消息(Messaging)**:Spring 支持消息传递,如 JMS(Java Message Service),允许分布式系统中的异步通信和解耦。
5. **模块(Modules)**:Spring Framework 包含多个模块,如数据访问/集成(Data Access/Integration)、Web、Test 等,覆盖了数据库访问、Web 开发、测试支持等多个领域。
6. **Web 模块**:Spring MVC(Model-View-Controller)提供了 Web 应用的开发框架,支持 RESTful 风格的接口和多种视图技术。此外,Spring Boot 和 Spring Cloud 为微服务架构提供了便利。
7. **数据访问**:Spring 支持 JDBC、ORM(Object-Relational Mapping)框架如 Hibernate 和 JPA,以及对 NoSQL 数据库的集成。
8. **测试支持**:Spring 提供了测试工具和集成测试框架,如 @Autowired 注解用于自动装配测试环境,方便单元测试和集成测试。
9. **安全**:Spring Security(以前称为 Acegi Security)提供了一套完整的权限管理和认证框架,可以保护应用程序免受各种安全威胁。
10. **国际化和本地化(Internationalization, i18n)**:Spring 提供了支持多语言和文化环境的工具,帮助开发者构建全球化应用。
以上只是 Spring Framework 中的一小部分关键知识点,完整的文档会详细解释这些概念以及如何在实际项目中应用它们。对于 Spring 开发者来说,深入理解和掌握这些内容至关重要,可以提升开发效率和应用质量。
Spring Framework Reference Documentation
4.3.22.RELEASE Spring Framework xvi
21.3. Using Marshaller and Unmarshaller ................................................................. 471
21.4. XML configuration namespace ........................................................................ 473
21.5. JAXB ............................................................................................................. 473
Jaxb2Marshaller ............................................................................................. 473
XML configuration namespace ................................................................ 474
21.6. Castor ........................................................................................................... 474
CastorMarshaller ............................................................................................ 474
Mapping ......................................................................................................... 475
XML configuration namespace ................................................................ 475
21.7. XMLBeans ..................................................................................................... 476
XmlBeansMarshaller ....................................................................................... 476
XML configuration namespace ................................................................ 476
21.8. JiBX .............................................................................................................. 476
JibxMarshaller ................................................................................................ 477
XML configuration namespace ................................................................ 477
21.9. XStream ........................................................................................................ 477
XStreamMarshaller ......................................................................................... 477
VI. The Web .......................................................................................................................... 479
22. Web MVC framework ................................................................................................ 480
22.1. Introduction to Spring Web MVC framework .................................................... 480
Features of Spring Web MVC ......................................................................... 480
Pluggability of other MVC implementations ...................................................... 482
22.2. The DispatcherServlet .................................................................................... 482
Special Bean Types In the WebApplicationContext ........................................... 486
Default DispatcherServlet Configuration ........................................................... 487
DispatcherServlet Processing Sequence .......................................................... 487
22.3. Implementing Controllers ................................................................................ 489
Defining a controller with @Controller .............................................................. 489
Mapping Requests With @RequestMapping ..................................................... 490
Composed @RequestMapping Variants ................................................... 491
@Controller and AOP Proxying ............................................................... 492
New Support Classes for @RequestMapping methods in Spring MVC 3.1 .. 492
URI Template Patterns ........................................................................... 493
URI Template Patterns with Regular Expressions ..................................... 494
Path Patterns ......................................................................................... 494
Path Pattern Comparison ........................................................................ 495
Path Patterns with Placeholders .............................................................. 495
Suffix Pattern Matching ........................................................................... 495
Suffix Pattern Matching and RFD ............................................................ 495
Matrix Variables ...................................................................................... 496
Consumable Media Types ....................................................................... 498
Producible Media Types .......................................................................... 498
Request Parameters and Header Values ................................................. 499
HTTP HEAD and HTTP OPTIONS .......................................................... 499
Defining @RequestMapping handler methods .................................................. 500
Supported method argument types .......................................................... 500
Supported method return types ............................................................... 502
Binding request parameters to method parameters with @RequestParam ... 503
Mapping the request body with the @RequestBody annotation .................. 504
Mapping the response body with the @ResponseBody annotation ............. 505
Spring Framework Reference Documentation
4.3.22.RELEASE Spring Framework xvii
Creating REST Controllers with the @RestController annotation ................ 506
Using HttpEntity ...................................................................................... 506
Using @ModelAttribute on a method ....................................................... 506
Using @ModelAttribute on a method argument ......................................... 507
Using @SessionAttributes to store model attributes in the HTTP session
between requests ................................................................................... 509
Using @SessionAttribute to access pre-existing global session attributes .... 510
Using @RequestAttribute to access request attributes .............................. 510
Working with "application/x-www-form-urlencoded" data ............................ 510
Mapping cookie values with the @CookieValue annotation ........................ 511
Mapping request header attributes with the @RequestHeader annotation ... 511
Method Parameters And Type Conversion ............................................... 512
Customizing WebDataBinder initialization ................................................. 512
Advising controllers with @ControllerAdvice and @RestControllerAdvice .... 513
Jackson Serialization View Support ......................................................... 514
Jackson JSONP Support ........................................................................ 515
Asynchronous Request Processing .................................................................. 516
Exception Handling for Async Requests ................................................... 517
Intercepting Async Requests ................................................................... 518
HTTP Streaming ..................................................................................... 518
HTTP Streaming With Server-Sent Events ............................................... 518
HTTP Streaming Directly To The OutputStream ....................................... 519
Configuring Asynchronous Request Processing ........................................ 519
Testing Controllers ......................................................................................... 520
22.4. Handler mappings .......................................................................................... 520
Intercepting requests with a HandlerInterceptor ................................................ 521
22.5. Resolving views ............................................................................................. 523
Resolving views with the ViewResolver interface .............................................. 523
Chaining ViewResolvers ................................................................................. 525
Redirecting to Views ....................................................................................... 525
RedirectView .......................................................................................... 526
The redirect: prefix ................................................................................. 527
The forward: prefix ................................................................................. 527
ContentNegotiatingViewResolver ..................................................................... 527
22.6. Using flash attributes ..................................................................................... 529
22.7. Building URIs ................................................................................................. 530
Building URIs to Controllers and methods ........................................................ 531
Working with "Forwarded" and "X-Forwarded-*" Headers .................................. 532
Building URIs to Controllers and methods from views ....................................... 532
22.8. Using locales ................................................................................................. 533
Obtaining Time Zone Information .................................................................... 534
AcceptHeaderLocaleResolver .......................................................................... 534
CookieLocaleResolver ..................................................................................... 534
SessionLocaleResolver ................................................................................... 534
LocaleChangeInterceptor ................................................................................ 535
22.9. Using themes ................................................................................................ 535
Overview of themes ........................................................................................ 535
Defining themes ............................................................................................. 535
Theme resolvers ............................................................................................. 536
22.10. Spring’s multipart (file upload) support ........................................................... 536
Spring Framework Reference Documentation
4.3.22.RELEASE Spring Framework xviii
Introduction .................................................................................................... 536
Using a MultipartResolver with Commons FileUpload ........................................ 537
Using a MultipartResolver with Servlet 3.0 ....................................................... 537
Handling a file upload in a form ...................................................................... 537
Handling a file upload request from programmatic clients .................................. 538
22.11. Handling exceptions ..................................................................................... 539
HandlerExceptionResolver .............................................................................. 539
@ExceptionHandler ........................................................................................ 540
Handling Standard Spring MVC Exceptions ...................................................... 541
Annotating Business Exceptions With @ResponseStatus .................................. 542
Customizing the Default Servlet Container Error Page ...................................... 542
22.12. Web Security ............................................................................................... 543
22.13. Convention over configuration support ........................................................... 543
The Controller ControllerClassNameHandlerMapping ........................................ 543
The Model ModelMap (ModelAndView) ............................................................ 544
Default view name .......................................................................................... 545
22.14. HTTP caching support .................................................................................. 547
Cache-Control HTTP header ........................................................................... 547
HTTP caching support for static resources ....................................................... 547
Support for the Cache-Control, ETag and Last-Modified response headers in
Controllers ...................................................................................................... 548
Shallow ETag support ..................................................................................... 549
22.15. Code-based Servlet container initialization ..................................................... 550
22.16. Configuring Spring MVC ............................................................................... 552
Enabling the MVC Java Config or the MVC XML Namespace ............................ 552
Customizing the Provided Configuration ........................................................... 554
Conversion and Formatting ............................................................................. 554
Validation ....................................................................................................... 555
Interceptors .................................................................................................... 556
Content Negotiation ........................................................................................ 557
View Controllers ............................................................................................. 558
View Resolvers .............................................................................................. 558
Serving of Resources ..................................................................................... 559
Default Servlet ................................................................................................ 562
Path Matching ................................................................................................ 563
Message Converters ....................................................................................... 563
Advanced Customizations with MVC Java Config ............................................. 564
Advanced Customizations with the MVC Namespace ........................................ 565
23. View Technologies .................................................................................................... 566
23.1. Introduction .................................................................................................... 566
23.2. Thymeleaf ..................................................................................................... 566
23.3. Groovy Markup .............................................................................................. 566
Configuration .................................................................................................. 566
Example ......................................................................................................... 567
23.4. Velocity & FreeMarker .................................................................................... 567
Dependencies ................................................................................................ 567
Context configuration ...................................................................................... 567
Creating templates ......................................................................................... 568
Advanced configuration ................................................................................... 568
velocity.properties ................................................................................... 568
Spring Framework Reference Documentation
4.3.22.RELEASE Spring Framework xix
FreeMarker ............................................................................................. 569
Bind support and form handling ....................................................................... 569
The bind macros .................................................................................... 569
Simple binding ........................................................................................ 570
Form input generation macros ................................................................. 570
HTML escaping and XHTML compliance ................................................. 574
23.5. JSP & JSTL .................................................................................................. 574
View resolvers ................................................................................................ 575
'Plain-old' JSPs versus JSTL ........................................................................... 575
Spring’s JSP tag library .................................................................................. 575
Spring’s form tag library .................................................................................. 575
Configuration .......................................................................................... 576
The form tag .......................................................................................... 576
The input tag .......................................................................................... 577
The checkbox tag ................................................................................... 577
The checkboxes tag ............................................................................... 579
The radiobutton tag ................................................................................ 580
The radiobuttons tag ............................................................................... 580
The password tag ................................................................................... 580
The select tag ........................................................................................ 580
The option tag ........................................................................................ 581
The options tag ...................................................................................... 581
The textarea tag ..................................................................................... 582
The hidden tag ....................................................................................... 582
The errors tag ........................................................................................ 582
HTTP method conversion ........................................................................ 584
HTML5 tags ........................................................................................... 585
23.6. Script views ................................................................................................... 585
Requirements ................................................................................................. 586
Script templates .............................................................................................. 586
23.7. XML Marshalling ............................................................................................ 588
23.8. Tiles .............................................................................................................. 588
Dependencies ................................................................................................ 588
Configuration .................................................................................................. 588
UrlBasedViewResolver ............................................................................ 589
ResourceBundleViewResolver ................................................................. 589
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 590
23.9. XSLT ............................................................................................................. 590
Beans ............................................................................................................ 591
Controller ....................................................................................................... 591
Transformation ............................................................................................... 592
23.10. Document views: PDF, Excel ........................................................................ 592
Introduction .................................................................................................... 592
Configuration .................................................................................................. 593
View definition ................................................................................................ 593
Controller ....................................................................................................... 593
Excel views .................................................................................................... 593
PDF views ..................................................................................................... 595
23.11. JasperReports .............................................................................................. 595
Dependencies ................................................................................................ 595
Spring Framework Reference Documentation
4.3.22.RELEASE Spring Framework xx
Configuration .................................................................................................. 595
Configuring the ViewResolver .................................................................. 596
Configuring the Views ............................................................................. 596
About Report Files .................................................................................. 596
Using JasperReportsMultiFormatView ...................................................... 596
Populating the ModelAndView ......................................................................... 597
Working with sub-reports ................................................................................ 598
Configuring sub-report files ..................................................................... 598
Configuring sub-report data sources ........................................................ 599
Configuring exporter parameters ..................................................................... 599
23.12. Feed views: RSS, Atom ............................................................................... 600
23.13. JSON Mapping View .................................................................................... 600
23.14. XML Mapping View ...................................................................................... 601
24. Integrating with other web frameworks ....................................................................... 602
24.1. Introduction .................................................................................................... 602
24.2. Common configuration ................................................................................... 603
24.3. JavaServer Faces 1.2 .................................................................................... 604
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 604
FacesContextUtils ........................................................................................... 604
24.4. Apache Struts 2.x .......................................................................................... 604
24.5. Tapestry 5.x .................................................................................................. 605
24.6. Further Resources ......................................................................................... 605
25. Portlet MVC Framework ............................................................................................ 606
25.1. Introduction .................................................................................................... 606
Controllers - The C in MVC ............................................................................ 607
Views - The V in MVC .................................................................................... 607
Web-scoped beans ......................................................................................... 607
25.2. The DispatcherPortlet ..................................................................................... 607
25.3. The ViewRendererServlet ............................................................................... 609
25.4. Controllers ..................................................................................................... 610
AbstractController and PortletContentGenerator ............................................... 611
Other simple controllers .................................................................................. 612
Command Controllers ..................................................................................... 612
PortletWrappingController ................................................................................ 613
25.5. Handler mappings .......................................................................................... 613
PortletModeHandlerMapping ............................................................................ 614
ParameterHandlerMapping .............................................................................. 614
PortletModeParameterHandlerMapping ............................................................ 615
Adding HandlerInterceptors ............................................................................. 615
HandlerInterceptorAdapter ............................................................................... 616
ParameterMappingInterceptor .......................................................................... 616
25.6. Views and resolving them .............................................................................. 616
25.7. Multipart (file upload) support ......................................................................... 616
Using the PortletMultipartResolver ................................................................... 617
Handling a file upload in a form ...................................................................... 617
25.8. Handling exceptions ....................................................................................... 621
25.9. Annotation-based controller configuration ........................................................ 621
Setting up the dispatcher for annotation support ............................................... 621
Defining a controller with @Controller .............................................................. 622
Mapping requests with @RequestMapping ....................................................... 622
剩余915页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2019-11-14 上传
2020-12-21 上传
2019-09-18 上传
2020-02-28 上传
2020-07-17 上传
2021-05-25 上传
hajunma
- 粉丝: 1
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 火炬连体网络在MNIST的2D嵌入实现示例
- Angular插件增强Application Insights JavaScript SDK功能
- 实时三维重建:InfiniTAM的ros驱动应用
- Spring与Mybatis整合的配置与实践
- Vozy前端技术测试深入体验与模板参考
- React应用实现语音转文字功能介绍
- PHPMailer-6.6.4: PHP邮件收发类库的详细介绍
- Felineboard:为猫主人设计的交互式仪表板
- PGRFileManager:功能强大的开源Ajax文件管理器
- Pytest-Html定制测试报告与源代码封装教程
- Angular开发与部署指南:从创建到测试
- BASIC-BINARY-IPC系统:进程间通信的非阻塞接口
- LTK3D: Common Lisp中的基础3D图形实现
- Timer-Counter-Lister:官方源代码及更新发布
- Galaxia REST API:面向地球问题的解决方案
- Node.js模块:随机动物实例教程与源码解析
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功