没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架入门与参考指南
Spring框架入门与参考指南
5星 · 超过95%的资源 需积分: 9 1 下载量 7 浏览量
更新于2024-07-24
收藏 4.55MB PDF 举报
"Spring开发文档,3.2.5.RELEASE版本,由多位知名开发者共同编著,涵盖了Spring Framework的核心概念、模块划分、使用场景以及依赖管理和命名规范等内容,旨在帮助初学者深入理解并掌握Spring框架。"
Spring Framework是Java平台上一个广泛使用的开源应用框架,以其依赖注入(Dependency Injection,DI)和控制反转(Inversion of Control,IoC)为核心特性,简化了企业级应用的开发。DI允许开发者将组件的依赖关系通过外部配置来管理,而不是在代码中硬编码,这使得组件更易于测试和复用。
Spring Framework主要分为以下几个模块:
1. **核心容器**:这是Spring的基础,包括Bean工厂和ApplicationContext,它们负责创建、配置和管理应用中的对象。Bean工厂提供了基本的DI功能,而ApplicationContext则添加了更多企业级服务,如事件传播、国际化支持等。
2. **数据访问/集成**:该模块支持与数据库的交互,包括JDBC抽象层、ORM(对象关系映射)支持,如Hibernate和JPA,以及OXM(对象XML映射)支持,如JAXB和Castor。
3. **Web**:Spring提供了多种Web应用的支持,如Spring MVC,用于构建RESTful Web服务和Web应用,还有Spring WebFlux,支持响应式编程模型。
4. **面向切面编程(AOP)和Instrumentation**:AOP模块允许开发者定义“切面”(跨越多个类的方法),实现代码的解耦,例如日志记录、事务管理。Instrumentation则提供类加载器和代理相关的工具,用于在运行时修改类或类装载器的行为。
5. **测试**:Spring提供了一套测试框架,支持单元测试和集成测试,包括模拟对象、测试上下文框架和Web应用测试支持。
Spring Framework的使用场景多样,可以应用于各种类型的应用中,包括但不限于:
- 单体应用:Spring的IoC和AOP特性可以简化服务的创建和管理。
- 微服务:Spring Boot简化了微服务的开发,提供了快速启动和自动配置的功能。
- 数据访问:通过ORM和JDBC支持,Spring可以轻松处理数据库操作。
- Web服务:Spring MVC和WebFlux可构建高性能的RESTful API。
- 测试:内置的测试支持使得编写和执行测试更加便捷。
此外,Spring Framework遵循一定的依赖管理和命名规范,这有助于保持代码的整洁和一致性。例如,使用标准的命名约定来标识bean,以及通过Maven或Gradle的依赖管理来控制库版本,以避免版本冲突。
Spring Framework通过其强大的模块化设计和丰富的功能,为Java开发者提供了一个高效、灵活的开发平台,无论是初学者还是经验丰富的开发者,都能从中受益。
Spring Framework
3.2.5.RELEASE
Spring Framework
Reference Documentation xvi
'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 ............................................................................. 516
The radiobutton tag ........................................................................... 516
The radiobuttons tag ......................................................................... 517
The password tag ................................................................................. 517
The select tag ..................................................................................... 517
The option tag ..................................................................................... 518
The options tag ................................................................................... 518
The textarea tag ................................................................................. 519
The hidden tag ..................................................................................... 519
The errors tag ..................................................................................... 519
HTTP Method Conversion ....................................................................... 522
HTML5 Tags .......................................................................................... 523
18.3. Tiles .............................................................................................................. 523
Dependencies ................................................................................................ 523
How to integrate Tiles ..................................................................................... 523
UrlBasedViewResolver .................................................................... 524
ResourceBundleViewResolver ........................................................ 524
SimpleSpringPreparerFactory and
SpringBeanPreparerFactory ............................................................ 524
18.4. Velocity & FreeMarker .................................................................................... 525
Dependencies ................................................................................................ 525
Context configuration ...................................................................................... 525
Creating templates ......................................................................................... 526
Advanced configuration ................................................................................... 527
velocity.properties ................................................................................... 527
FreeMarker ............................................................................................. 527
Bind support and form handling ....................................................................... 528
The bind macros .................................................................................... 528
Simple binding ........................................................................................ 528
Form input generation macros ................................................................. 529
HTML escaping and XHTML compliance ................................................. 533
18.5. XSLT ............................................................................................................. 534
My First Words ............................................................................................... 534
Bean definitions ...................................................................................... 534
Standard MVC controller code ................................................................. 534
Convert the model data to XML ............................................................... 535
Defining the view properties .................................................................... 535
Document transformation ........................................................................ 536
Summary ....................................................................................................... 536
18.6. Document views (PDF/Excel) .......................................................................... 537
Introduction .................................................................................................... 537
Configuration and setup .................................................................................. 537
Document view definitions ....................................................................... 537
Spring Framework
3.2.5.RELEASE
Spring Framework
Reference Documentation xvii
Controller code ....................................................................................... 537
Subclassing for Excel views .................................................................... 537
Subclassing for PDF views ..................................................................... 539
18.7. JasperReports ............................................................................................... 540
Dependencies ................................................................................................ 540
Configuration .................................................................................................. 540
Configuring the ViewResolver .............................................................. 540
Configuring the Views ............................................................................ 540
About Report Files .................................................................................. 541
Using JasperReportsMultiFormatView ............................................. 541
Populating the ModelAndView ....................................................................... 542
Working with Sub-Reports ............................................................................... 543
Configuring Sub-Report Files .................................................................. 543
Configuring Sub-Report Data Sources ..................................................... 544
Configuring Exporter Parameters ..................................................................... 544
18.8. Feed Views ................................................................................................... 544
18.9. XML Marshalling View .................................................................................... 545
18.10. JSON Mapping View .................................................................................... 546
19. Integrating with other web frameworks ....................................................................... 547
19.1. Introduction .................................................................................................... 547
19.2. Common configuration ................................................................................... 548
19.3. JavaServer Faces 1.1 and 1.2 ........................................................................ 549
DelegatingVariableResolver (JSF 1.1/1.2) ........................................................ 549
SpringBeanVariableResolver (JSF 1.1/1.2) ....................................................... 550
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 550
FacesContextUtils ........................................................................................... 550
19.4. Apache Struts 1.x and 2.x .............................................................................. 551
ContextLoaderPlugin ....................................................................................... 551
DelegatingRequestProcessor ................................................................... 552
DelegatingActionProxy ............................................................................ 552
ActionSupport Classes .................................................................................... 553
19.5. WebWork 2.x ................................................................................................. 553
19.6. Tapestry 3.x and 4.x ...................................................................................... 554
Injecting Spring-managed beans ..................................................................... 555
Dependency Injecting Spring Beans into Tapestry pages ........................... 557
Component definition files ....................................................................... 558
Adding abstract accessors ...................................................................... 559
Dependency Injecting Spring Beans into Tapestry pages - Tapestry 4.x
style ....................................................................................................... 561
19.7. Further Resources ......................................................................................... 562
20. Portlet MVC Framework ............................................................................................ 563
20.1. Introduction .................................................................................................... 563
Controllers - The C in MVC ............................................................................ 564
Views - The V in MVC .................................................................................... 564
Web-scoped beans ......................................................................................... 564
20.2. The DispatcherPortlet ............................................................................ 564
20.3. The ViewRendererServlet ........................................................................ 566
20.4. Controllers ..................................................................................................... 567
AbstractController and PortletContentGenerator ............................. 568
Other simple controllers .................................................................................. 569
Spring Framework
3.2.5.RELEASE
Spring Framework
Reference Documentation xviii
Command Controllers ..................................................................................... 569
PortletWrappingController .................................................................... 570
20.5. Handler mappings .......................................................................................... 570
PortletModeHandlerMapping .................................................................... 571
ParameterHandlerMapping ........................................................................ 571
PortletModeParameterHandlerMapping .................................................. 572
Adding HandlerInterceptors ..................................................................... 572
HandlerInterceptorAdapter .................................................................... 573
ParameterMappingInterceptor ................................................................ 573
20.6. Views and resolving them .............................................................................. 573
20.7. Multipart (file upload) support ......................................................................... 574
Using the PortletMultipartResolver ....................................................... 574
Handling a file upload in a form ...................................................................... 575
20.8. Handling exceptions ....................................................................................... 578
20.9. Annotation-based controller configuration ........................................................ 578
Setting up the dispatcher for annotation support ............................................... 578
Defining a controller with @Controller .......................................................... 579
Mapping requests with @RequestMapping ..................................................... 580
Supported handler method arguments ............................................................. 581
Binding request parameters to method parameters with @RequestParam .......... 583
Providing a link to data from the model with @ModelAttribute ....................... 583
Specifying attributes to store in a Session with @SessionAttributes ............. 584
Customizing WebDataBinder initialization ...................................................... 584
Customizing data binding with @InitBinder .......................................... 584
Configuring a custom WebBindingInitializer ................................... 585
20.10. Portlet application deployment ...................................................................... 585
VI. Integration ......................................................................................................................... 586
21. Remoting and web services using Spring ................................................................... 587
21.1. Introduction .................................................................................................... 587
21.2. Exposing services using RMI .......................................................................... 588
Exporting the service using the RmiServiceExporter ................................... 588
Linking in the service at the client ................................................................... 589
21.3. Using Hessian or Burlap to remotely call services via HTTP .............................. 589
Wiring up the DispatcherServlet for Hessian and co. ................................. 589
Exposing your beans by using the HessianServiceExporter ....................... 590
Linking in the service on the client .................................................................. 591
Using Burlap .................................................................................................. 591
Applying HTTP basic authentication to a service exposed through Hessian or
Burlap ............................................................................................................ 591
21.4. Exposing services using HTTP invokers .......................................................... 592
Exposing the service object ............................................................................ 592
Linking in the service at the client ................................................................... 593
21.5. Web services ................................................................................................. 593
Exposing servlet-based web services using JAX-RPC ....................................... 594
Accessing web services using JAX-RPC .......................................................... 595
Registering JAX-RPC Bean Mappings ............................................................. 597
Registering your own JAX-RPC Handler .......................................................... 597
Exposing servlet-based web services using JAX-WS ........................................ 598
Exporting standalone web services using JAX-WS ........................................... 599
Exporting web services using the JAX-WS RI's Spring support .......................... 600
Spring Framework
3.2.5.RELEASE
Spring Framework
Reference Documentation xix
Accessing web services using JAX-WS ........................................................... 600
21.6. JMS .............................................................................................................. 601
Server-side configuration ................................................................................. 602
Client-side configuration .................................................................................. 603
21.7. Auto-detection is not implemented for remote interfaces ................................... 604
21.8. Considerations when choosing a technology .................................................... 604
21.9. Accessing RESTful services on the Client ....................................................... 605
RestTemplate ................................................................................................. 605
Working with the URI .............................................................................. 607
Dealing with request and response headers ............................................. 608
HTTP Message Conversion ............................................................................ 608
StringHttpMessageConverter ................................................................... 609
FormHttpMessageConverter .................................................................... 609
ByteArrayHttpMessageConverter ............................................................. 609
MarshallingHttpMessageConverter ........................................................... 609
MappingJackson2HttpMessageConverter (or
MappingJacksonHttpMessageConverter with Jackson 1.x) ........................ 610
SourceHttpMessageConverter ................................................................. 610
BufferedImageHttpMessageConverter ...................................................... 610
22. Enterprise JavaBeans (EJB) integration ..................................................................... 611
22.1. Introduction .................................................................................................... 611
22.2. Accessing EJBs ............................................................................................. 611
Concepts ........................................................................................................ 611
Accessing local SLSBs ................................................................................... 611
Accessing remote SLSBs ................................................................................ 613
Accessing EJB 2.x SLSBs versus EJB 3 SLSBs ............................................... 613
22.3. Using Spring's EJB implementation support classes ......................................... 614
EJB 2.x base classes ..................................................................................... 614
EJB 3 injection interceptor .............................................................................. 616
23. JMS (Java Message Service) .................................................................................... 618
23.1. Introduction .................................................................................................... 618
23.2. Using Spring JMS .......................................................................................... 618
JmsTemplate ................................................................................................ 618
Connections ................................................................................................... 619
Caching Messaging Resources ............................................................... 619
SingleConnectionFactory ......................................................................... 619
CachingConnectionFactory ...................................................................... 620
Destination Management ................................................................................. 620
Message Listener Containers .......................................................................... 621
SimpleMessageListenerContainer ............................................................ 621
DefaultMessageListenerContainer ............................................................ 621
Transaction management ................................................................................ 621
23.3. Sending a Message ....................................................................................... 622
Using Message Converters ............................................................................. 623
SessionCallback and ProducerCallback ................................................ 624
23.4. Receiving a message ..................................................................................... 624
Synchronous Reception .................................................................................. 624
Asynchronous Reception - Message-Driven POJOs .......................................... 624
The SessionAwareMessageListener interface ........................................... 625
The MessageListenerAdapter ................................................................... 626
Spring Framework
3.2.5.RELEASE
Spring Framework
Reference Documentation xx
Processing messages within transactions ........................................................ 627
23.5. Support for JCA Message Endpoints ............................................................... 628
23.6. JMS Namespace Support ............................................................................... 630
24. JMX ......................................................................................................................... 634
24.1. Introduction .................................................................................................... 634
24.2. Exporting your beans to JMX .......................................................................... 634
Creating an MBeanServer ............................................................................. 636
Reusing an existing MBeanServer ................................................................. 636
Lazy-initialized MBeans ................................................................................... 637
Automatic registration of MBeans .................................................................... 637
Controlling the registration behavior ................................................................. 638
24.3. Controlling the management interface of your beans ........................................ 639
The MBeanInfoAssembler Interface ............................................................. 639
Using Source-Level Metadata (JDK 5.0 annotations) ........................................ 639
Source-Level Metadata Types ......................................................................... 641
The AutodetectCapableMBeanInfoAssembler interface ............................ 643
Defining management interfaces using Java interfaces ..................................... 643
Using MethodNameBasedMBeanInfoAssembler ........................................... 645
24.4. Controlling the ObjectNames for your beans .................................................. 645
Reading ObjectNames from Properties ...................................................... 645
Using the MetadataNamingStrategy ........................................................... 646
Configuring annotation based MBean export .................................................... 647
24.5. JSR-160 Connectors ...................................................................................... 648
Server-side Connectors ................................................................................... 648
Client-side Connectors .................................................................................... 649
JMX over Burlap/Hessian/SOAP ...................................................................... 649
24.6. Accessing MBeans via Proxies ....................................................................... 649
24.7. Notifications ................................................................................................... 650
Registering Listeners for Notifications .............................................................. 650
Publishing Notifications ................................................................................... 654
24.8. Further Resources ......................................................................................... 656
25. JCA CCI .................................................................................................................. 657
25.1. Introduction .................................................................................................... 657
25.2. Configuring CCI ............................................................................................. 657
Connector configuration .................................................................................. 657
ConnectionFactory configuration in Spring ................................................. 658
Configuring CCI connections ........................................................................... 658
Using a single CCI connection ........................................................................ 659
25.3. Using Spring's CCI access support ................................................................. 660
Record conversion .......................................................................................... 660
The CciTemplate ......................................................................................... 661
DAO support .................................................................................................. 662
Automatic output record generation ................................................................. 662
Summary ....................................................................................................... 663
Using a CCI Connection and Interaction directly ...................................... 664
Example for CciTemplate usage ................................................................... 665
25.4. Modeling CCI access as operation objects ...................................................... 667
MappingRecordOperation .......................................................................... 667
MappingCommAreaOperation ...................................................................... 667
Automatic output record generation ................................................................. 668
剩余846页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2012-05-28 上传
2012-06-23 上传
2023-05-16 上传
2017-01-12 上传
541 浏览量
love刘明
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言数组操作:高度检查器编程实践
- 基于Swift开发的嘉定单车LBS iOS应用项目解析
- 钗头凤声乐表演的二度创作分析报告
- 分布式数据库特训营全套教程资料
- JavaScript开发者Robert Bindar的博客平台
- MATLAB投影寻踪代码教程及文件解压缩指南
- HTML5拖放实现的RPSLS游戏教程
- HT://Dig引擎接口,Ampoliros开源模块应用
- 全面探测服务器性能与PHP环境的iprober PHP探针v0.024
- 新版提醒应用v2:基于MongoDB的数据存储
- 《我的世界》东方大陆1.12.2材质包深度体验
- Hypercore Promisifier: JavaScript中的回调转换为Promise包装器
- 探索开源项目Artifice:Slyme脚本与技巧游戏
- Matlab机器人学习代码解析与笔记分享
- 查尔默斯大学计算物理作业HP2解析
- GitHub问题管理新工具:GIRA-crx插件介绍
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功