没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架参考指南:依赖注入与模块解析
"Spring Framework Reference Documentation 4.1.1 RELEASE"
Spring Framework 是一个全面的、开源的应用程序开发框架,主要用于简化Java企业级应用的开发。它由Rod Johnson等人创建,并在2004年至2014年间持续更新。这个框架的核心特性包括依赖注入(Dependency Injection,DI)和控制反转(Inversion of Control,IoC),这两个概念是Spring框架的基础。
1. **依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)**
- **DI**:这是一种设计模式,它允许对象之间的关系在运行时被定义,而不是硬编码在类内部。通过外部容器(如Spring框架)管理对象及其依赖,可以实现松耦合,增强代码的可测试性和可维护性。
- **IoC**:IoC是DI的另一种表述,强调应用程序的控制权从组件本身转移到了容器。在Spring中,容器负责创建对象、管理它们的生命周期以及建立对象间的依赖关系。
2. **核心容器(Core Container)**
- Spring的核心部分是核心容器,主要包括ApplicationContext和BeanFactory。ApplicationContext提供了高级的上下文功能,而BeanFactory是Spring的最基础容器,负责实例化、配置、组装和管理对象。
3. **AOP和Instrumentation**
- **AOP(面向切面编程)**:Spring支持面向切面编程,允许开发者定义“切面”,这些切面封装了横切关注点,如日志、事务管理等,从而减少了代码的重复性。
- **Instrumentation**:提供类加载器和代理相关的工具,用于类的热部署、内存分析等,增强了对应用程序的监控和调试能力。
4. **Messaging**
- Spring提供了一种消息传递模型,支持发布/订阅和点对点的消息传递,可以与各种消息中间件(如JMS)集成,实现解耦的通信机制。
5. **数据访问/集成(Data Access/Integration)**
- Spring提供了对多种数据库访问技术的支持,包括JDBC、ORM(Object-Relational Mapping)框架如Hibernate和MyBatis,以及NoSQL数据库的支持。它还包含了对事务管理的全面支持,无论是编程式还是声明式的事务管理。
6. **Web层**
- Spring MVC(Model-View-Controller)是Spring提供的Web框架,它使得构建Web应用变得更加简单,提供模型绑定、数据验证、本地化和主题支持等功能。
- Spring Web Services则专注于创建基于SOAP和RESTful的Web服务。
7. **模块(Modules)**
- Spring框架由多个模块组成,如Spring Core、Spring Beans、Spring AOP、Spring JDBC、Spring ORM、Spring Web、Spring Web MVC等,每个模块都专注于特定的职责,可以根据项目需求选择使用。
Spring框架的灵活性和广泛的社区支持使得它成为了Java开发中的主流选择。开发者可以通过XML配置、注解或Java配置来声明和管理bean,同时,Spring Boot的引入进一步简化了Spring应用的启动和配置过程。Spring Framework提供了一个强大且灵活的平台,帮助开发者更高效地构建健壮的企业级应用。
Spring Framework Reference Documentation
4.1.1.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 ....................................................... 486
Handling a file upload in a form ...................................................................... 487
Handling a file upload request from programmatic clients .................................. 488
17.11. Handling exceptions ..................................................................................... 488
HandlerExceptionResolver .............................................................................. 488
@ExceptionHandler ........................................................................................ 489
Handling Standard Spring MVC Exceptions ...................................................... 489
Annotating Business Exceptions With @ResponseStatus .................................. 490
Customizing the Default Servlet Container Error Page ...................................... 491
17.12. Web Security ............................................................................................... 491
17.13. Convention over configuration support ........................................................... 491
The Controller ControllerClassNameHandlerMapping ........................................ 492
The Model ModelMap (ModelAndView) ............................................................ 493
The View - RequestToViewNameTranslator ..................................................... 494
17.14. ETag support ............................................................................................... 495
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 ........................................................... 499
Interceptors .................................................................................................... 500
Content Negotiation ........................................................................................ 501
View Controllers ............................................................................................. 502
View Resolvers .............................................................................................. 502
Serving of Resources ..................................................................................... 503
Falling Back On the "Default" Servlet To Serve Resources ................................ 505
Path Matching ................................................................................................ 506
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.1.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.1.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.1.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 ........................................... 581
Overview of STOMP ....................................................................................... 582
Enable STOMP over WebSocket ..................................................................... 583
Flow of Messages .......................................................................................... 584
Annotation Message Handling ......................................................................... 586
Sending Messages ......................................................................................... 587
Simple Broker ................................................................................................ 587
Full-Featured Broker ....................................................................................... 587
Connections To Full-Featured Broker .............................................................. 589
Using Dot as Separator in @MessageMapping Destinations ............................. 589
Authentication ................................................................................................. 590
User Destinations ........................................................................................... 591
Listening To ApplicationContext Events and Intercepting Messages ................... 592
WebSocket Scope .......................................................................................... 594
Configuration and Performance ....................................................................... 595
Runtime Monitoring ......................................................................................... 597
Testing Annotated Controller Methods ............................................................. 598
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.1.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页未读,继续阅读
2020-02-28 上传
2019-06-13 上传
2019-09-18 上传
2020-07-17 上传
2011-04-15 上传
2019-05-30 上传
Maximus_Yuan
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 迷宫商店
- lcdlibai,有趣的c语言源码,c语言项目
- perceiver-pytorch:在Pytorch中实现感知器(具有迭代注意的一般感知)
- Antena Zagreb Chrome Player-crx插件
- eslint-config
- python的学习笔记
- gerenciador-reservas
- wn21-discussion9-panjalee:wn21-discussion9-panjalee由GitHub Classroom创建
- 可二次开发MYSQLbishe015.zip
- 安迪兒美女報時-crx插件
- serv,c语言项目开源码,c语言项目
- imaqutils:为支持的图像采集设备查找硬件和创建对象的便捷功能。-matlab开发
- Python实用程序代码
- 附加功能:Node JS附加功能
- attentio-desk-app:使用Electron的Attentio桌面应用程序
- mocktail:免费,轻量级,可以运行带有漂亮界面的本地dockerized模拟服务器
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功