没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring Framework 4.1.6参考文档
"Spring Framework 4.1.6.RELEASE官方文档"
Spring Framework 是一个全面的、开源的应用程序框架,主要用于简化Java开发。它由Rod Johnson、Juergen Hoeller等多位开发者共同创建,并由SpringSource(现属VMware)维护。这个框架的核心特性是依赖注入(Dependency Injection,DI)和控制反转(Inversion of Control,IoC),它们是Spring的基础,旨在减少代码间的耦合,提高应用的可测试性和可维护性。
**1. 依赖注入和控制反转**
依赖注入是Spring Framework中的核心概念,它允许组件之间通过接口而非硬编码的方式来相互依赖。通过容器管理组件的生命周期和依赖关系,可以使得代码更加灵活,易于测试和扩展。控制反转是指将对象的创建和组装过程交给容器来处理,而不是由对象自己决定其依赖。
**2. Spring 模块**
Spring Framework由多个模块组成,这些模块提供了丰富的功能:
- **Core Container**:包括Core和 Beans模块,提供了DI和IoC容器的基础,以及Bean工厂和ApplicationContext接口。
- **AOP and Instrumentation**:支持面向切面编程(Aspect-Oriented Programming, AOP),用于编写横切关注点,如日志、事务管理等;Instrumentation模块则提供类加载器和应用服务器相关的工具。
- **Messaging**:这部分通常指的是Spring的Message Broker模块,支持消息传递,如JMS(Java Message Service)。
- **Data Access/Integration**:包含了ORM(Object-Relational Mapping)、JDBC、Transaction、DAO等模块,为数据库访问和集成提供了支持。
**3. 数据访问**
在数据访问方面,Spring提供了对多种持久化技术的支持,包括JDBC抽象层、ORM框架集成(如Hibernate、JPA)和O/R映射。它还引入了声明式事务管理,使得事务处理变得更加简单。
**4. AOP支持**
面向切面编程允许开发者将关注点从业务逻辑中分离出来,例如,事务管理、日志记录和安全检查等。Spring提供了基于代理的AOP实现,同时也支持基于注解的AOP配置。
**5. Web层支持**
Spring的Web模块包括MVC(Model-View-Controller)框架,提供了模型视图控制器架构,用于构建可重用、松耦合的Web应用程序。此外,Spring还与许多Web框架如Struts、JSF等集成,提供了统一的编程模型。
**6. 测试**
Spring提供了强大的测试支持,包括单元测试和集成测试。Spring Test模块可以帮助开发者轻松地创建和运行Spring应用的测试用例。
**7. 安全**
Spring Security(原名Acegi Security)模块提供了全面的安全管理框架,包括认证、授权、CSRF防护等功能。
**8. 自动配置和Bootstrapping**
Spring Boot简化了Spring应用的初始化和配置过程,通过自动配置特性,可以根据依赖自动设置bean。Spring Boot也提供了独立运行的Spring应用能力,无需额外的服务器配置。
Spring Framework是一个全面的框架,涵盖了从基础服务到Web应用开发的各个方面,旨在提升Java开发的效率和质量。其强大的DI和AOP机制,以及丰富的模块,使其成为现代企业级应用开发的首选框架之一。
Spring Framework Reference Documentation
4.1.6.RELEASE Spring Framework xvi
17.10. Spring’s multipart (file upload) support ........................................................... 487
Introduction .................................................................................................... 487
Using a MultipartResolver with Commons FileUpload ........................................ 487
Using a MultipartResolver with Servlet 3.0 ....................................................... 488
Handling a file upload in a form ...................................................................... 488
Handling a file upload request from programmatic clients .................................. 489
17.11. Handling exceptions ..................................................................................... 490
HandlerExceptionResolver .............................................................................. 490
@ExceptionHandler ........................................................................................ 490
Handling Standard Spring MVC Exceptions ...................................................... 491
Annotating Business Exceptions With @ResponseStatus .................................. 492
Customizing the Default Servlet Container Error Page ...................................... 492
17.12. Web Security ............................................................................................... 493
17.13. Convention over configuration support ........................................................... 493
The Controller ControllerClassNameHandlerMapping ........................................ 493
The Model ModelMap (ModelAndView) ............................................................ 494
The View - RequestToViewNameTranslator ..................................................... 496
17.14. ETag support ............................................................................................... 497
17.15. Code-based Servlet container initialization ..................................................... 497
17.16. Configuring Spring MVC ............................................................................... 499
Enabling the MVC Java Config or the MVC XML Namespace ............................ 499
Customizing the Provided Configuration ........................................................... 501
Interceptors .................................................................................................... 501
Content Negotiation ........................................................................................ 502
View Controllers ............................................................................................. 503
View Resolvers .............................................................................................. 503
Serving of Resources ..................................................................................... 505
Falling Back On the "Default" Servlet To Serve Resources ................................ 507
Path Matching ................................................................................................ 508
Advanced Customizations with MVC Java Config ............................................. 508
Advanced Customizations with the MVC Namespace ........................................ 509
18. View technologies ..................................................................................................... 510
18.1. Introduction .................................................................................................... 510
18.2. JSP & JSTL .................................................................................................. 510
View resolvers ................................................................................................ 510
Plain-old JSPs versus JSTL ............................................................................ 511
Additional tags facilitating development ............................................................ 511
Using Spring’s form tag library ........................................................................ 511
Configuration .......................................................................................... 511
The form tag .......................................................................................... 511
The input tag .......................................................................................... 513
The checkbox tag ................................................................................... 513
The checkboxes tag ............................................................................... 515
The radiobutton tag ................................................................................ 515
The radiobuttons tag ............................................................................... 515
The password tag ................................................................................... 516
The select tag ........................................................................................ 516
The option tag ........................................................................................ 516
The options tag ...................................................................................... 517
The textarea tag ..................................................................................... 518
Spring Framework Reference Documentation
4.1.6.RELEASE Spring Framework xvii
The hidden tag ....................................................................................... 518
The errors tag ........................................................................................ 518
HTTP Method Conversion ....................................................................... 520
HTML5 Tags .......................................................................................... 521
18.3. Tiles .............................................................................................................. 521
Dependencies ................................................................................................ 521
How to integrate Tiles ..................................................................................... 521
UrlBasedViewResolver ............................................................................ 522
ResourceBundleViewResolver ................................................................. 522
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 523
18.4. Velocity & FreeMarker .................................................................................... 523
Dependencies ................................................................................................ 524
Context configuration ...................................................................................... 524
Creating templates ......................................................................................... 524
Advanced configuration ................................................................................... 525
velocity.properties ................................................................................... 525
FreeMarker ............................................................................................. 525
Bind support and form handling ....................................................................... 526
The bind macros .................................................................................... 526
Simple binding ........................................................................................ 526
Form input generation macros ................................................................. 527
HTML escaping and XHTML compliance ................................................. 530
18.5. XSLT ............................................................................................................. 531
My First Words ............................................................................................... 531
Bean definitions ...................................................................................... 531
Standard MVC controller code ................................................................. 531
Convert the model data to XML ............................................................... 532
Defining the view properties .................................................................... 532
Document transformation ........................................................................ 533
Summary ....................................................................................................... 533
18.6. Document views (PDF/Excel) .......................................................................... 534
Introduction .................................................................................................... 534
Configuration and setup .................................................................................. 534
Document view definitions ....................................................................... 534
Controller code ....................................................................................... 534
Subclassing for Excel views .................................................................... 534
Subclassing for PDF views ..................................................................... 536
18.7. JasperReports ............................................................................................... 536
Dependencies ................................................................................................ 536
Configuration .................................................................................................. 536
Configuring the ViewResolver .................................................................. 537
Configuring the Views ............................................................................. 537
About Report Files .................................................................................. 537
Using JasperReportsMultiFormatView ...................................................... 537
Populating the ModelAndView ......................................................................... 538
Working with Sub-Reports ............................................................................... 539
Configuring Sub-Report Files .................................................................. 539
Configuring Sub-Report Data Sources ..................................................... 540
Configuring Exporter Parameters ..................................................................... 540
18.8. Feed Views ................................................................................................... 541
Spring Framework Reference Documentation
4.1.6.RELEASE Spring Framework xviii
18.9. XML Marshalling View .................................................................................... 541
18.10. JSON Mapping View .................................................................................... 542
18.11. XML Mapping View ...................................................................................... 542
19. Integrating with other web frameworks ....................................................................... 543
19.1. Introduction .................................................................................................... 543
19.2. Common configuration ................................................................................... 544
19.3. JavaServer Faces 1.2 .................................................................................... 545
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 545
FacesContextUtils ........................................................................................... 545
19.4. Apache Struts 2.x .......................................................................................... 545
19.5. Tapestry 5.x .................................................................................................. 546
19.6. Further Resources ......................................................................................... 546
20. Portlet MVC Framework ............................................................................................ 547
20.1. Introduction .................................................................................................... 547
Controllers - The C in MVC ............................................................................ 548
Views - The V in MVC .................................................................................... 548
Web-scoped beans ......................................................................................... 548
20.2. The DispatcherPortlet ..................................................................................... 548
20.3. The ViewRendererServlet ............................................................................... 550
20.4. Controllers ..................................................................................................... 551
AbstractController and PortletContentGenerator ............................................... 552
Other simple controllers .................................................................................. 553
Command Controllers ..................................................................................... 553
PortletWrappingController ................................................................................ 554
20.5. Handler mappings .......................................................................................... 554
PortletModeHandlerMapping ............................................................................ 555
ParameterHandlerMapping .............................................................................. 555
PortletModeParameterHandlerMapping ............................................................ 556
Adding HandlerInterceptors ............................................................................. 556
HandlerInterceptorAdapter ............................................................................... 557
ParameterMappingInterceptor .......................................................................... 557
20.6. Views and resolving them .............................................................................. 557
20.7. Multipart (file upload) support ......................................................................... 557
Using the PortletMultipartResolver ................................................................... 558
Handling a file upload in a form ...................................................................... 558
20.8. Handling exceptions ....................................................................................... 562
20.9. Annotation-based controller configuration ........................................................ 562
Setting up the dispatcher for annotation support ............................................... 562
Defining a controller with @Controller .............................................................. 563
Mapping requests with @RequestMapping ....................................................... 563
Supported handler method arguments ............................................................. 565
Binding request parameters to method parameters with @RequestParam .......... 566
Providing a link to data from the model with @ModelAttribute ............................ 566
Specifying attributes to store in a Session with @SessionAttributes .................... 567
Customizing WebDataBinder initialization ......................................................... 567
Customizing data binding with @InitBinder ............................................... 568
Configuring a custom WebBindingInitializer .............................................. 568
20.10. Portlet application deployment ...................................................................... 568
21. WebSocket Support .................................................................................................. 570
21.1. Introduction .................................................................................................... 570
Spring Framework Reference Documentation
4.1.6.RELEASE Spring Framework xix
WebSocket Fallback Options ........................................................................... 570
A Messaging Architecture ............................................................................... 571
Sub-Protocol Support in WebSocket ................................................................ 571
Should I Use WebSocket? .............................................................................. 571
21.2. WebSocket API ............................................................................................. 572
Create and Configure a WebSocketHandler ..................................................... 572
Customizing the WebSocket Handshake .......................................................... 573
WebSocketHandler Decoration ........................................................................ 574
Deployment Considerations ............................................................................. 574
Configuring the WebSocket Engine ................................................................. 575
Configuring allowed origins ............................................................................. 577
21.3. SockJS Fallback Options ................................................................................ 578
Overview of SockJS ....................................................................................... 578
Enable SockJS ............................................................................................... 579
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 580
Heartbeat Messages ....................................................................................... 581
Servlet 3 Async Requests ............................................................................... 581
CORS Headers for SockJS ............................................................................. 582
SockJS Client ................................................................................................. 582
21.4. STOMP Over WebSocket Messaging Architecture ........................................... 584
Overview of STOMP ....................................................................................... 584
Enable STOMP over WebSocket ..................................................................... 585
Flow of Messages .......................................................................................... 587
Annotation Message Handling ......................................................................... 588
Sending Messages ......................................................................................... 589
Simple Broker ................................................................................................ 590
Full-Featured Broker ....................................................................................... 590
Connections To Full-Featured Broker .............................................................. 591
Using Dot as Separator in @MessageMapping Destinations ............................. 592
Authentication ................................................................................................. 593
User Destinations ........................................................................................... 594
Listening To ApplicationContext Events and Intercepting Messages ................... 595
WebSocket Scope .......................................................................................... 596
Configuration and Performance ....................................................................... 597
Runtime Monitoring ......................................................................................... 600
Testing Annotated Controller Methods ............................................................. 601
VI. Integration ......................................................................................................................... 602
22. Remoting and web services using Spring ................................................................... 603
22.1. Introduction .................................................................................................... 603
22.2. Exposing services using RMI .......................................................................... 604
Exporting the service using the RmiServiceExporter ......................................... 604
Linking in the service at the client ................................................................... 605
22.3. Using Hessian or Burlap to remotely call services via HTTP .............................. 605
Wiring up the DispatcherServlet for Hessian and co. ......................................... 605
Exposing your beans by using the HessianServiceExporter ............................... 606
Linking in the service on the client .................................................................. 606
Using Burlap .................................................................................................. 607
Applying HTTP basic authentication to a service exposed through Hessian or
Burlap ............................................................................................................ 607
22.4. Exposing services using HTTP invokers .......................................................... 607
Spring Framework Reference Documentation
4.1.6.RELEASE Spring Framework xx
Exposing the service object ............................................................................ 608
Linking in the service at the client ................................................................... 609
22.5. Web services ................................................................................................. 609
Exposing servlet-based web services using JAX-WS ........................................ 609
Exporting standalone web services using JAX-WS ........................................... 610
Exporting web services using the JAX-WS RI’s Spring support .......................... 611
Accessing web services using JAX-WS ........................................................... 611
22.6. JMS .............................................................................................................. 612
Server-side configuration ................................................................................. 613
Client-side configuration .................................................................................. 613
22.7. AMQP ........................................................................................................... 614
22.8. Auto-detection is not implemented for remote interfaces ................................... 614
22.9. Considerations when choosing a technology .................................................... 615
22.10. Accessing RESTful services on the Client ..................................................... 615
RestTemplate ................................................................................................. 615
Working with the URI .............................................................................. 618
Dealing with request and response headers ............................................. 619
Jackson JSON Views support ................................................................. 619
HTTP Message Conversion ............................................................................ 619
StringHttpMessageConverter ................................................................... 620
FormHttpMessageConverter .................................................................... 620
ByteArrayHttpMessageConverter ............................................................. 620
MarshallingHttpMessageConverter ........................................................... 620
MappingJackson2HttpMessageConverter ................................................. 620
MappingJackson2XmlHttpMessageConverter ........................................... 621
SourceHttpMessageConverter ................................................................. 621
BufferedImageHttpMessageConverter ...................................................... 621
Async RestTemplate ....................................................................................... 621
23. Enterprise JavaBeans (EJB) integration ..................................................................... 623
23.1. Introduction .................................................................................................... 623
23.2. Accessing EJBs ............................................................................................. 623
Concepts ........................................................................................................ 623
Accessing local SLSBs ................................................................................... 623
Accessing remote SLSBs ................................................................................ 625
Accessing EJB 2.x SLSBs versus EJB 3 SLSBs ............................................... 625
23.3. Using Spring’s EJB implementation support classes ......................................... 626
EJB 3 injection interceptor .............................................................................. 626
24. JMS (Java Message Service) .................................................................................... 627
24.1. Introduction .................................................................................................... 627
24.2. Using Spring JMS .......................................................................................... 627
JmsTemplate .................................................................................................. 627
Connections ................................................................................................... 628
Caching Messaging Resources ............................................................... 628
SingleConnectionFactory ......................................................................... 629
CachingConnectionFactory ...................................................................... 629
Destination Management ................................................................................. 629
Message Listener Containers .......................................................................... 630
SimpleMessageListenerContainer ............................................................ 630
DefaultMessageListenerContainer ............................................................ 630
Transaction management ................................................................................ 631
剩余842页未读,继续阅读
2019-11-14 上传
2019-06-13 上传
2020-02-28 上传
2020-03-22 上传
2019-09-18 上传
2019-05-28 上传
2016-06-12 上传
little_胖
- 粉丝: 6
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的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直接复制
信息提交成功