没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架4.x新特性与核心容器深入解析
Spring框架4.x新特性与核心容器深入解析
5星 · 超过95%的资源 需积分: 17 4 下载量 11 浏览量
更新于2024-07-21
收藏 4.9MB PDF 举报
"Spring Framework Reference 4.1.2"
Spring框架是Java应用程序开发的核心工具,它提供了多种功能,如依赖注入(IoC),面向切面编程(AOP),以及丰富的核心容器和Web应用程序支持。这份文档详细介绍了Spring 4.x版本的特性,更新和使用方法。
在"不使用Commons Logging"部分,文档建议开发者避免使用Apache Commons Logging,转而使用更现代的日志记录解决方案,如SLF4J和Log4J。
"使用SLF4J"章节中,SLF4J(Simple Logging Facade for Java)被推荐作为日志适配器,因为它允许应用程序与各种日志框架(如Logback或Log4j)互操作,提供了更灵活的日志记录解决方案。
"使用Log4J"部分介绍了如何配置Spring应用来利用Log4J进行日志记录,Log4J是一个强大的、广泛使用的日志记录库,提供了高级的日志配置和管理功能。
"Spring Framework 4.x的新特性"部分概述了4.0版本的主要改进:
1. 改进了入门体验,使得新用户更容易上手。
2. 移除了已废弃的包和方法,保持框架的清洁和现代性。
3. 引入了对Java 8的支持,同时兼容Java 6和7。
4. 针对Java EE 6和7进行了优化,提升了企业级应用开发的兼容性。
5. 添加了Groovy Bean定义领域特定语言(DSL),简化了配置的编写。
6. 核心容器有所增强,包括Bean的管理和服务。
7. 提升了Web应用的性能和功能。
8. 引入了WebSocket、SockJS和STOMP消息传递技术,增强了实时通信能力。
9. 测试功能也得到了改进,使得测试更便捷和高效。
"核心技术"章节深入讨论了Spring框架的核心组件,尤其是IoC容器:
- IoC容器是Spring的核心,负责管理对象的生命周期和依赖关系。
- 容器概述涵盖了配置元数据、实例化容器、基于XML的配置元数据组合,以及如何使用容器获取和管理Bean。
- Bean的概述包括Bean的命名、别名、实例化(通过构造函数、静态工厂方法或实例工厂方法)以及依赖注入的概念。
- 依赖部分详细解释了依赖注入的不同方式(构造器注入和设值注入)以及依赖解析的过程。
这份文档是Spring Framework 4.0.0.RELEASE的参考文档,由多位贡献者共同编写,旨在帮助开发者深入理解并充分利用Spring框架的功能。
Spring Framework Reference Documentation
4.1.2.RELEASE Spring Framework xvi
17.10. Spring’s multipart (file upload) support ........................................................... 486
Introduction .................................................................................................... 486
Using a MultipartResolver with Commons FileUpload ........................................ 486
Using a MultipartResolver with Servlet 3.0 ....................................................... 487
Handling a file upload in a form ...................................................................... 487
Handling a file upload request from programmatic clients .................................. 488
17.11. Handling exceptions ..................................................................................... 489
HandlerExceptionResolver .............................................................................. 489
@ExceptionHandler ........................................................................................ 489
Handling Standard Spring MVC Exceptions ...................................................... 490
Annotating Business Exceptions With @ResponseStatus .................................. 491
Customizing the Default Servlet Container Error Page ...................................... 491
17.12. Web Security ............................................................................................... 492
17.13. Convention over configuration support ........................................................... 492
The Controller ControllerClassNameHandlerMapping ........................................ 492
The Model ModelMap (ModelAndView) ............................................................ 493
The View - RequestToViewNameTranslator ..................................................... 495
17.14. ETag support ............................................................................................... 496
17.15. Code-based Servlet container initialization ..................................................... 496
17.16. Configuring Spring MVC ............................................................................... 498
Enabling the MVC Java Config or the MVC XML Namespace ............................ 498
Customizing the Provided Configuration ........................................................... 500
Interceptors .................................................................................................... 500
Content Negotiation ........................................................................................ 501
View Controllers ............................................................................................. 502
View Resolvers .............................................................................................. 502
Serving of Resources ..................................................................................... 504
Falling Back On the "Default" Servlet To Serve Resources ................................ 506
Path Matching ................................................................................................ 507
Advanced Customizations with MVC Java Config ............................................. 507
Advanced Customizations with the MVC Namespace ........................................ 508
18. View technologies ..................................................................................................... 509
18.1. Introduction .................................................................................................... 509
18.2. JSP & JSTL .................................................................................................. 509
View resolvers ................................................................................................ 509
Plain-old JSPs versus JSTL ............................................................................ 510
Additional tags facilitating development ............................................................ 510
Using Spring’s form tag library ........................................................................ 510
Configuration .......................................................................................... 510
The form tag .......................................................................................... 510
The input tag .......................................................................................... 512
The checkbox tag ................................................................................... 512
The checkboxes tag ............................................................................... 514
The radiobutton tag ................................................................................ 514
The radiobuttons tag ............................................................................... 514
The password tag ................................................................................... 515
The select tag ........................................................................................ 515
The option tag ........................................................................................ 515
The options tag ...................................................................................... 516
The textarea tag ..................................................................................... 517
Spring Framework Reference Documentation
4.1.2.RELEASE Spring Framework xvii
The hidden tag ....................................................................................... 517
The errors tag ........................................................................................ 517
HTTP Method Conversion ....................................................................... 519
HTML5 Tags .......................................................................................... 520
18.3. Tiles .............................................................................................................. 520
Dependencies ................................................................................................ 520
How to integrate Tiles ..................................................................................... 520
UrlBasedViewResolver ............................................................................ 521
ResourceBundleViewResolver ................................................................. 521
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 522
18.4. Velocity & FreeMarker .................................................................................... 522
Dependencies ................................................................................................ 523
Context configuration ...................................................................................... 523
Creating templates ......................................................................................... 523
Advanced configuration ................................................................................... 524
velocity.properties ................................................................................... 524
FreeMarker ............................................................................................. 524
Bind support and form handling ....................................................................... 525
The bind macros .................................................................................... 525
Simple binding ........................................................................................ 525
Form input generation macros ................................................................. 526
HTML escaping and XHTML compliance ................................................. 529
18.5. XSLT ............................................................................................................. 530
My First Words ............................................................................................... 530
Bean definitions ...................................................................................... 530
Standard MVC controller code ................................................................. 530
Convert the model data to XML ............................................................... 531
Defining the view properties .................................................................... 531
Document transformation ........................................................................ 532
Summary ....................................................................................................... 532
18.6. Document views (PDF/Excel) .......................................................................... 533
Introduction .................................................................................................... 533
Configuration and setup .................................................................................. 533
Document view definitions ....................................................................... 533
Controller code ....................................................................................... 533
Subclassing for Excel views .................................................................... 533
Subclassing for PDF views ..................................................................... 535
18.7. JasperReports ............................................................................................... 535
Dependencies ................................................................................................ 535
Configuration .................................................................................................. 535
Configuring the ViewResolver .................................................................. 536
Configuring the Views ............................................................................. 536
About Report Files .................................................................................. 536
Using JasperReportsMultiFormatView ...................................................... 536
Populating the ModelAndView ......................................................................... 537
Working with Sub-Reports ............................................................................... 538
Configuring Sub-Report Files .................................................................. 538
Configuring Sub-Report Data Sources ..................................................... 539
Configuring Exporter Parameters ..................................................................... 539
18.8. Feed Views ................................................................................................... 540
Spring Framework Reference Documentation
4.1.2.RELEASE Spring Framework xviii
18.9. XML Marshalling View .................................................................................... 540
18.10. JSON Mapping View .................................................................................... 541
18.11. XML Mapping View ...................................................................................... 541
19. Integrating with other web frameworks ....................................................................... 542
19.1. Introduction .................................................................................................... 542
19.2. Common configuration ................................................................................... 543
19.3. JavaServer Faces 1.2 .................................................................................... 544
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 544
FacesContextUtils ........................................................................................... 544
19.4. Apache Struts 2.x .......................................................................................... 544
19.5. Tapestry 5.x .................................................................................................. 545
19.6. Further Resources ......................................................................................... 545
20. Portlet MVC Framework ............................................................................................ 546
20.1. Introduction .................................................................................................... 546
Controllers - The C in MVC ............................................................................ 547
Views - The V in MVC .................................................................................... 547
Web-scoped beans ......................................................................................... 547
20.2. The DispatcherPortlet ..................................................................................... 547
20.3. The ViewRendererServlet ............................................................................... 549
20.4. Controllers ..................................................................................................... 550
AbstractController and PortletContentGenerator ............................................... 551
Other simple controllers .................................................................................. 552
Command Controllers ..................................................................................... 552
PortletWrappingController ................................................................................ 553
20.5. Handler mappings .......................................................................................... 553
PortletModeHandlerMapping ............................................................................ 554
ParameterHandlerMapping .............................................................................. 554
PortletModeParameterHandlerMapping ............................................................ 555
Adding HandlerInterceptors ............................................................................. 555
HandlerInterceptorAdapter ............................................................................... 556
ParameterMappingInterceptor .......................................................................... 556
20.6. Views and resolving them .............................................................................. 556
20.7. Multipart (file upload) support ......................................................................... 556
Using the PortletMultipartResolver ................................................................... 557
Handling a file upload in a form ...................................................................... 557
20.8. Handling exceptions ....................................................................................... 561
20.9. Annotation-based controller configuration ........................................................ 561
Setting up the dispatcher for annotation support ............................................... 561
Defining a controller with @Controller .............................................................. 562
Mapping requests with @RequestMapping ....................................................... 562
Supported handler method arguments ............................................................. 564
Binding request parameters to method parameters with @RequestParam .......... 565
Providing a link to data from the model with @ModelAttribute ............................ 565
Specifying attributes to store in a Session with @SessionAttributes .................... 566
Customizing WebDataBinder initialization ......................................................... 566
Customizing data binding with @InitBinder ............................................... 567
Configuring a custom WebBindingInitializer .............................................. 567
20.10. Portlet application deployment ...................................................................... 567
21. WebSocket Support .................................................................................................. 569
21.1. Introduction .................................................................................................... 569
Spring Framework Reference Documentation
4.1.2.RELEASE Spring Framework xix
WebSocket Fallback Options ........................................................................... 569
A Messaging Architecture ............................................................................... 570
Sub-Protocol Support in WebSocket ................................................................ 570
Should I Use WebSocket? .............................................................................. 570
21.2. WebSocket API ............................................................................................. 571
Create and Configure a WebSocketHandler ..................................................... 571
Customizing the WebSocket Handshake .......................................................... 572
WebSocketHandler Decoration ........................................................................ 573
Deployment Considerations ............................................................................. 573
Configuring the WebSocket Engine ................................................................. 574
21.3. SockJS Fallback Options ................................................................................ 576
Overview of SockJS ....................................................................................... 576
Enable SockJS ............................................................................................... 577
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 578
Heartbeat Messages ....................................................................................... 579
Servlet 3 Async Requests ............................................................................... 579
CORS Headers for SockJS ............................................................................. 580
SockJS Client ................................................................................................. 580
21.4. STOMP Over WebSocket Messaging Architecture ........................................... 582
Overview of STOMP ....................................................................................... 582
Enable STOMP over WebSocket ..................................................................... 583
Flow of Messages .......................................................................................... 585
Annotation Message Handling ......................................................................... 586
Sending Messages ......................................................................................... 587
Simple Broker ................................................................................................ 588
Full-Featured Broker ....................................................................................... 588
Connections To Full-Featured Broker .............................................................. 589
Using Dot as Separator in @MessageMapping Destinations ............................. 590
Authentication ................................................................................................. 591
User Destinations ........................................................................................... 592
Listening To ApplicationContext Events and Intercepting Messages ................... 593
WebSocket Scope .......................................................................................... 594
Configuration and Performance ....................................................................... 595
Runtime Monitoring ......................................................................................... 598
Testing Annotated Controller Methods ............................................................. 599
VI. Integration ......................................................................................................................... 600
22. Remoting and web services using Spring ................................................................... 601
22.1. Introduction .................................................................................................... 601
22.2. Exposing services using RMI .......................................................................... 602
Exporting the service using the RmiServiceExporter ......................................... 602
Linking in the service at the client ................................................................... 603
22.3. Using Hessian or Burlap to remotely call services via HTTP .............................. 603
Wiring up the DispatcherServlet for Hessian and co. ......................................... 603
Exposing your beans by using the HessianServiceExporter ............................... 604
Linking in the service on the client .................................................................. 604
Using Burlap .................................................................................................. 605
Applying HTTP basic authentication to a service exposed through Hessian or
Burlap ............................................................................................................ 605
22.4. Exposing services using HTTP invokers .......................................................... 605
Exposing the service object ............................................................................ 606
Spring Framework Reference Documentation
4.1.2.RELEASE Spring Framework xx
Linking in the service at the client ................................................................... 607
22.5. Web services ................................................................................................. 607
Exposing servlet-based web services using JAX-WS ........................................ 607
Exporting standalone web services using JAX-WS ........................................... 608
Exporting web services using the JAX-WS RI’s Spring support .......................... 609
Accessing web services using JAX-WS ........................................................... 609
22.6. JMS .............................................................................................................. 610
Server-side configuration ................................................................................. 611
Client-side configuration .................................................................................. 611
22.7. AMQP ........................................................................................................... 612
22.8. Auto-detection is not implemented for remote interfaces ................................... 612
22.9. Considerations when choosing a technology .................................................... 613
22.10. Accessing RESTful services on the Client ..................................................... 613
RestTemplate ................................................................................................. 613
Working with the URI .............................................................................. 616
Dealing with request and response headers ............................................. 617
Jackson JSON Views support ................................................................. 617
HTTP Message Conversion ............................................................................ 617
StringHttpMessageConverter ................................................................... 618
FormHttpMessageConverter .................................................................... 618
ByteArrayHttpMessageConverter ............................................................. 618
MarshallingHttpMessageConverter ........................................................... 618
MappingJackson2HttpMessageConverter ................................................. 618
MappingJackson2XmlHttpMessageConverter ........................................... 619
SourceHttpMessageConverter ................................................................. 619
BufferedImageHttpMessageConverter ...................................................... 619
Async RestTemplate ....................................................................................... 619
23. Enterprise JavaBeans (EJB) integration ..................................................................... 621
23.1. Introduction .................................................................................................... 621
23.2. Accessing EJBs ............................................................................................. 621
Concepts ........................................................................................................ 621
Accessing local SLSBs ................................................................................... 621
Accessing remote SLSBs ................................................................................ 623
Accessing EJB 2.x SLSBs versus EJB 3 SLSBs ............................................... 623
23.3. Using Spring’s EJB implementation support classes ......................................... 624
EJB 3 injection interceptor .............................................................................. 624
24. JMS (Java Message Service) .................................................................................... 625
24.1. Introduction .................................................................................................... 625
24.2. Using Spring JMS .......................................................................................... 625
JmsTemplate .................................................................................................. 625
Connections ................................................................................................... 626
Caching Messaging Resources ............................................................... 626
SingleConnectionFactory ......................................................................... 627
CachingConnectionFactory ...................................................................... 627
Destination Management ................................................................................. 627
Message Listener Containers .......................................................................... 628
SimpleMessageListenerContainer ............................................................ 628
DefaultMessageListenerContainer ............................................................ 628
Transaction management ................................................................................ 629
24.3. Sending a Message ....................................................................................... 629
剩余840页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2014-11-26 上传
点击了解资源详情
点击了解资源详情
点击了解资源详情
点击了解资源详情
点击了解资源详情
lixiplus
- 粉丝: 53
- 资源: 44
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 深入浅出:自定义 Grunt 任务的实践指南
- 网络物理突变工具的多点路径规划实现与分析
- multifeed: 实现多作者间的超核心共享与同步技术
- C++商品交易系统实习项目详细要求
- macOS系统Python模块whl包安装教程
- 掌握fullstackJS:构建React框架与快速开发应用
- React-Purify: 实现React组件纯净方法的工具介绍
- deck.js:构建现代HTML演示的JavaScript库
- nunn:现代C++17实现的机器学习库开源项目
- Python安装包 Acquisition-4.12-cp35-cp35m-win_amd64.whl.zip 使用说明
- Amaranthus-tuberculatus基因组分析脚本集
- Ubuntu 12.04下Realtek RTL8821AE驱动的向后移植指南
- 掌握Jest环境下的最新jsdom功能
- CAGI Toolkit:开源Asterisk PBX的AGI应用开发
- MyDropDemo: 体验QGraphicsView的拖放功能
- 远程FPGA平台上的Quartus II17.1 LCD色块闪烁现象解析
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功