没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring Framework 4.0参考文档:依赖注入与核心模块
Spring Framework 4.0参考文档:依赖注入与核心模块
需积分: 2 0 下载量 135 浏览量
更新于2024-07-23
收藏 4.5MB PDF 举报
"这是关于Spring Framework 4.0的最新版参考文档,全英文电子档,由多位专家共同编著。"
Spring Framework是Java平台上广泛使用的轻量级框架,其4.0版本带来了许多改进和新特性。这个文档详细介绍了Spring的核心概念、模块划分以及实际应用场景。
1. **依赖注入(Dependency Injection,DI)与控制反转(Inversion of Control,IoC)**
- Spring的核心特性之一是依赖注入,它允许开发者声明式地管理对象之间的依赖关系,降低了组件之间的耦合度。
- 控制反转是DI的一种实现方式,Spring通过反转对象创建和管理的控制权,使得组件的配置和组件本身分离,提高了代码的可测试性和可维护性。
2. **Spring Framework的模块**
- **Core Container**:包括核心容器(如ApplicationContext)和Bean工厂,提供bean定义、生命周期管理和装配的基础设施。
- **Data Access/Integration**:支持数据库访问,如JDBC、ORM(Hibernate、JPA)和OXM(Object-XML Mapping)等。
- **Web**:包含Spring MVC和WebSocket支持,用于构建Web应用程序。
- **AOP and Instrumentation**:提供了面向切面编程(Aspect-Oriented Programming,AOP),用于实现如日志、事务管理等功能。
- **Test**:提供测试支持,包括单元测试和集成测试,简化了测试代码的编写。
3. **使用场景**
- Spring可以用于各种用途,包括企业级应用、Web服务、微服务等。它可以作为服务层的容器,处理业务逻辑,也可以配合MVC框架处理Web请求。
- 它还支持多种数据访问技术,可以方便地与数据库进行交互,同时提供事务管理,确保数据的一致性。
4. **依赖管理和命名约定**
- Spring有严格的依赖管理和命名规则,以确保不同模块间的协同工作。开发者可以借助这些规则轻松地集成第三方库,减少冲突。
5. **Spring Data**
- Spring Data项目旨在简化数据访问层的开发,支持多种数据存储,如关系数据库、NoSQL和搜索引擎等。它提供了统一的API,减少了重复的CRUD操作代码。
6. **Spring Boot**
- 虽然不在4.0的直接描述中,但Spring Boot在Spring 4.x时代开始流行,它简化了Spring应用的启动和配置,是基于Spring的应用快速开发的工具。
7. **Spring Security**
- Spring Security是Spring生态中的安全框架,提供了身份验证、授权等功能,保护Web应用的安全。
8. **Spring Cloud**
- Spring Cloud为基于Spring的应用提供了开发分布式系统(如配置管理、服务发现、断路器、智能路由、微代理、控制总线等)的工具集。
Spring Framework 4.0文档详尽地阐述了这个框架的各个方面,是学习和使用Spring不可或缺的参考资料。无论是新手还是经验丰富的开发者,都可以从中受益匪浅。
Spring Framework
4.0.0.M2
Spring Framework
Reference Documentation xvi
The input tag ....................................................................................... 511
The checkbox tag ................................................................................. 511
The checkboxes tag ............................................................................. 514
The radiobutton tag ........................................................................... 514
The radiobuttons tag ......................................................................... 515
The password tag ................................................................................. 515
The select tag ..................................................................................... 515
The option tag ..................................................................................... 516
The options tag ................................................................................... 516
The textarea tag ................................................................................. 517
The hidden tag ..................................................................................... 517
The errors tag ..................................................................................... 517
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 ............................................................ 522
18.4. Velocity & FreeMarker .................................................................................... 523
Dependencies ................................................................................................ 523
Context configuration ...................................................................................... 523
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 ................................................. 531
18.5. XSLT ............................................................................................................. 532
My First Words ............................................................................................... 532
Bean definitions ...................................................................................... 532
Standard MVC controller code ................................................................. 532
Convert the model data to XML ............................................................... 533
Defining the view properties .................................................................... 533
Document transformation ........................................................................ 534
Summary ....................................................................................................... 534
18.6. Document views (PDF/Excel) .......................................................................... 535
Introduction .................................................................................................... 535
Configuration and setup .................................................................................. 535
Document view definitions ....................................................................... 535
Controller code ....................................................................................... 535
Subclassing for Excel views .................................................................... 535
Subclassing for PDF views ..................................................................... 537
18.7. JasperReports ............................................................................................... 538
Dependencies ................................................................................................ 538
Spring Framework
4.0.0.M2
Spring Framework
Reference Documentation xvii
Configuration .................................................................................................. 538
Configuring the ViewResolver .............................................................. 538
Configuring the Views ............................................................................ 538
About Report Files .................................................................................. 539
Using JasperReportsMultiFormatView ............................................. 539
Populating the ModelAndView ....................................................................... 540
Working with Sub-Reports ............................................................................... 541
Configuring Sub-Report Files .................................................................. 541
Configuring Sub-Report Data Sources ..................................................... 542
Configuring Exporter Parameters ..................................................................... 542
18.8. Feed Views ................................................................................................... 542
18.9. XML Marshalling View .................................................................................... 543
18.10. JSON Mapping View .................................................................................... 544
19. Integrating with other web frameworks ....................................................................... 545
19.1. Introduction .................................................................................................... 545
19.2. Common configuration ................................................................................... 546
19.3. JavaServer Faces 1.1 and 1.2 ........................................................................ 547
DelegatingVariableResolver (JSF 1.1/1.2) ........................................................ 547
SpringBeanVariableResolver (JSF 1.1/1.2) ....................................................... 548
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 548
FacesContextUtils ........................................................................................... 548
19.4. Apache Struts 1.x and 2.x .............................................................................. 549
ContextLoaderPlugin ....................................................................................... 549
DelegatingRequestProcessor ................................................................... 550
DelegatingActionProxy ............................................................................ 550
ActionSupport Classes .................................................................................... 551
19.5. WebWork 2.x ................................................................................................. 551
19.6. Tapestry 3.x and 4.x ...................................................................................... 552
Injecting Spring-managed beans ..................................................................... 553
Dependency Injecting Spring Beans into Tapestry pages ........................... 555
Component definition files ....................................................................... 556
Adding abstract accessors ...................................................................... 557
Dependency Injecting Spring Beans into Tapestry pages - Tapestry 4.x
style ....................................................................................................... 559
19.7. Further Resources ......................................................................................... 560
20. Portlet MVC Framework ............................................................................................ 561
20.1. Introduction .................................................................................................... 561
Controllers - The C in MVC ............................................................................ 562
Views - The V in MVC .................................................................................... 562
Web-scoped beans ......................................................................................... 562
20.2. The DispatcherPortlet ............................................................................ 562
20.3. The ViewRendererServlet ........................................................................ 564
20.4. Controllers ..................................................................................................... 565
AbstractController and PortletContentGenerator ............................. 566
Other simple controllers .................................................................................. 567
Command Controllers ..................................................................................... 567
PortletWrappingController .................................................................... 568
20.5. Handler mappings .......................................................................................... 568
PortletModeHandlerMapping .................................................................... 569
ParameterHandlerMapping ........................................................................ 569
Spring Framework
4.0.0.M2
Spring Framework
Reference Documentation xviii
PortletModeParameterHandlerMapping .................................................. 570
Adding HandlerInterceptors ..................................................................... 570
HandlerInterceptorAdapter .................................................................... 571
ParameterMappingInterceptor ................................................................ 571
20.6. Views and resolving them .............................................................................. 571
20.7. Multipart (file upload) support ......................................................................... 572
Using the PortletMultipartResolver ....................................................... 572
Handling a file upload in a form ...................................................................... 573
20.8. Handling exceptions ....................................................................................... 576
20.9. Annotation-based controller configuration ........................................................ 576
Setting up the dispatcher for annotation support ............................................... 576
Defining a controller with @Controller .......................................................... 577
Mapping requests with @RequestMapping ..................................................... 578
Supported handler method arguments ............................................................. 579
Binding request parameters to method parameters with @RequestParam .......... 581
Providing a link to data from the model with @ModelAttribute ....................... 581
Specifying attributes to store in a Session with @SessionAttributes ............. 582
Customizing WebDataBinder initialization ...................................................... 582
Customizing data binding with @InitBinder .......................................... 582
Configuring a custom WebBindingInitializer ................................... 583
20.10. Portlet application deployment ...................................................................... 583
VI. Integration ......................................................................................................................... 584
21. Remoting and web services using Spring ................................................................... 585
21.1. Introduction .................................................................................................... 585
21.2. Exposing services using RMI .......................................................................... 586
Exporting the service using the RmiServiceExporter ................................... 586
Linking in the service at the client ................................................................... 587
21.3. Using Hessian or Burlap to remotely call services via HTTP .............................. 587
Wiring up the DispatcherServlet for Hessian and co. ................................. 587
Exposing your beans by using the HessianServiceExporter ....................... 588
Linking in the service on the client .................................................................. 589
Using Burlap .................................................................................................. 589
Applying HTTP basic authentication to a service exposed through Hessian or
Burlap ............................................................................................................ 589
21.4. Exposing services using HTTP invokers .......................................................... 590
Exposing the service object ............................................................................ 590
Linking in the service at the client ................................................................... 591
21.5. Web services ................................................................................................. 591
Exposing servlet-based web services using JAX-WS ........................................ 592
Exporting standalone web services using JAX-WS ........................................... 593
Exporting web services using the JAX-WS RI's Spring support .......................... 593
Accessing web services using JAX-WS ........................................................... 594
21.6. JMS .............................................................................................................. 595
Server-side configuration ................................................................................. 595
Client-side configuration .................................................................................. 596
21.7. Auto-detection is not implemented for remote interfaces ................................... 597
21.8. Considerations when choosing a technology .................................................... 597
21.9. Accessing RESTful services on the Client ....................................................... 598
RestTemplate ................................................................................................. 598
Working with the URI .............................................................................. 600
Spring Framework
4.0.0.M2
Spring Framework
Reference Documentation xix
Dealing with request and response headers ............................................. 601
HTTP Message Conversion ............................................................................ 601
StringHttpMessageConverter ................................................................... 602
FormHttpMessageConverter .................................................................... 602
ByteArrayHttpMessageConverter ............................................................. 602
MarshallingHttpMessageConverter ........................................................... 602
MappingJackson2HttpMessageConverter (or
MappingJacksonHttpMessageConverter with Jackson 1.x) ........................ 603
SourceHttpMessageConverter ................................................................. 603
BufferedImageHttpMessageConverter ...................................................... 603
22. Enterprise JavaBeans (EJB) integration ..................................................................... 604
22.1. Introduction .................................................................................................... 604
22.2. Accessing EJBs ............................................................................................. 604
Concepts ........................................................................................................ 604
Accessing local SLSBs ................................................................................... 604
Accessing remote SLSBs ................................................................................ 606
Accessing EJB 2.x SLSBs versus EJB 3 SLSBs ............................................... 606
22.3. Using Spring's EJB implementation support classes ......................................... 607
EJB 3 injection interceptor .............................................................................. 607
23. JMS (Java Message Service) .................................................................................... 608
23.1. Introduction .................................................................................................... 608
23.2. Using Spring JMS .......................................................................................... 608
JmsTemplate ................................................................................................ 608
Connections ................................................................................................... 609
Caching Messaging Resources ............................................................... 609
SingleConnectionFactory ......................................................................... 609
CachingConnectionFactory ...................................................................... 610
Destination Management ................................................................................. 610
Message Listener Containers .......................................................................... 611
SimpleMessageListenerContainer ............................................................ 611
DefaultMessageListenerContainer ............................................................ 611
Transaction management ................................................................................ 611
23.3. Sending a Message ....................................................................................... 612
Using Message Converters ............................................................................. 613
SessionCallback and ProducerCallback ................................................ 614
23.4. Receiving a message ..................................................................................... 614
Synchronous Reception .................................................................................. 614
Asynchronous Reception - Message-Driven POJOs .......................................... 614
The SessionAwareMessageListener interface ........................................... 615
The MessageListenerAdapter ................................................................... 616
Processing messages within transactions ........................................................ 617
23.5. Support for JCA Message Endpoints ............................................................... 618
23.6. JMS Namespace Support ............................................................................... 620
24. JMX ......................................................................................................................... 624
24.1. Introduction .................................................................................................... 624
24.2. Exporting your beans to JMX .......................................................................... 624
Creating an MBeanServer ............................................................................. 626
Reusing an existing MBeanServer ................................................................. 626
Lazy-initialized MBeans ................................................................................... 627
Automatic registration of MBeans .................................................................... 627
Spring Framework
4.0.0.M2
Spring Framework
Reference Documentation xx
Controlling the registration behavior ................................................................. 628
24.3. Controlling the management interface of your beans ........................................ 629
The MBeanInfoAssembler Interface ............................................................. 629
Using Source-Level Metadata (JDK 5.0 annotations) ........................................ 629
Source-Level Metadata Types ......................................................................... 631
The AutodetectCapableMBeanInfoAssembler interface ............................ 633
Defining management interfaces using Java interfaces ..................................... 633
Using MethodNameBasedMBeanInfoAssembler ........................................... 635
24.4. Controlling the ObjectNames for your beans .................................................. 635
Reading ObjectNames from Properties ...................................................... 635
Using the MetadataNamingStrategy ........................................................... 636
Configuring annotation based MBean export .................................................... 637
24.5. JSR-160 Connectors ...................................................................................... 638
Server-side Connectors ................................................................................... 638
Client-side Connectors .................................................................................... 639
JMX over Burlap/Hessian/SOAP ...................................................................... 639
24.6. Accessing MBeans via Proxies ....................................................................... 639
24.7. Notifications ................................................................................................... 640
Registering Listeners for Notifications .............................................................. 640
Publishing Notifications ................................................................................... 644
24.8. Further Resources ......................................................................................... 646
25. JCA CCI .................................................................................................................. 647
25.1. Introduction .................................................................................................... 647
25.2. Configuring CCI ............................................................................................. 647
Connector configuration .................................................................................. 647
ConnectionFactory configuration in Spring ................................................. 648
Configuring CCI connections ........................................................................... 648
Using a single CCI connection ........................................................................ 649
25.3. Using Spring's CCI access support ................................................................. 650
Record conversion .......................................................................................... 650
The CciTemplate ......................................................................................... 651
DAO support .................................................................................................. 652
Automatic output record generation ................................................................. 652
Summary ....................................................................................................... 653
Using a CCI Connection and Interaction directly ...................................... 654
Example for CciTemplate usage ................................................................... 655
25.4. Modeling CCI access as operation objects ...................................................... 657
MappingRecordOperation .......................................................................... 657
MappingCommAreaOperation ...................................................................... 657
Automatic output record generation ................................................................. 658
Summary ....................................................................................................... 658
Example for MappingRecordOperation usage ............................................. 658
Example for MappingCommAreaOperation usage ......................................... 660
25.5. Transactions .................................................................................................. 662
26. Email ....................................................................................................................... 663
26.1. Introduction .................................................................................................... 663
26.2. Usage ........................................................................................................... 663
Basic MailSender and SimpleMailMessage usage ..................................... 664
Using the JavaMailSender and the MimeMessagePreparator .................... 665
26.3. Using the JavaMail MimeMessageHelper ...................................................... 666
剩余836页未读,继续阅读
2017-07-22 上传
2010-04-01 上传
1803 浏览量
623 浏览量
1656 浏览量
374 浏览量
小炮的玫瑰
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Java毕业设计项目:校园二手交易网站开发指南
- Blaseball Plus插件开发与构建教程
- Deno Express:模仿Node.js Express的Deno Web服务器解决方案
- coc-snippets: 强化coc.nvim代码片段体验
- Java面向对象编程语言特性解析与学生信息管理系统开发
- 掌握Java实现硬盘链接技术:LinkDisks深度解析
- 基于Springboot和Vue的Java网盘系统开发
- jMonkeyEngine3 SDK:Netbeans集成的3D应用开发利器
- Python家庭作业指南与实践技巧
- Java企业级Web项目实践指南
- Eureka注册中心与Go客户端使用指南
- TsinghuaNet客户端:跨平台校园网联网解决方案
- 掌握lazycsv:C++中高效解析CSV文件的单头库
- FSDAF遥感影像时空融合python实现教程
- Envato Markets分析工具扩展:监控销售与评论
- Kotlin实现NumPy绑定:提升数组数据处理性能
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功