没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring 3.1.1官方教程:依赖注入与模块化详解
Spring 3.1.1官方教程:依赖注入与模块化详解
需积分: 10 3 下载量 106 浏览量
更新于2024-07-24
收藏 3.4MB PDF 举报
本篇文档是Spring 3.1.1版本的官方使用手册,涵盖了Spring框架的全面介绍和关键特性。Spring Framework是由Rod Johnson等人在2004年至2011年期间开发的一套流行的轻量级开源应用框架,主要用于简化企业级Java应用的开发、依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)。
**第1章:Spring框架概述**
- **1.1 Dependency Injection和Inversion of Control (IoC)**: 这部分阐述了Spring如何通过IoC机制管理对象之间的依赖关系,使得代码更加模块化和可维护。DI允许组件之间通过接口而非实例直接交互,降低了耦合度,并促进了代码的复用和灵活性。
- **1.2 框架模块**:
- **核心容器(Core Container)**:负责创建、管理对象和它们之间的依赖关系。
- **数据访问/集成(Data Access/Integration)**:提供数据源管理和ORM支持,如JDBC、Hibernate等,便于开发者处理数据库操作。
- **Web**:Spring MVC和Spring WebFlux等模块,用于构建Web应用程序,包括请求处理、视图渲染和前端支持。
- **面向切面编程(AOP)和动态代理**:允许在不修改原有代码的情况下添加横切关注点,如日志记录、事务管理等。
- **测试**:Spring提供了测试工具和框架,如Spring Boot的自动配置和Mockito等,方便单元测试和集成测试。
**1.3 使用场景**:文档详细列举了Spring在实际项目中的应用场景,可能包括服务层解耦、模块化开发、自动化测试、以及与其他技术栈的整合,如RESTful API、WebSocket、微服务架构等。
**第2章:依赖管理和命名约定**
- **Spring Dependencies and Depending on Spring**:讲解如何在项目中管理Spring框架及其依赖,包括Maven和Ivy等构建工具的集成,确保组件之间的协调一致。
- **Logging**:讨论了Spring对日志框架的支持,如Logback或log4j,以及如何配置和使用内置的日志功能。
本手册对于深入理解和使用Spring 3.1.1版本具有很高的参考价值,无论是初学者还是经验丰富的开发者,都能从中找到所需的信息来提升开发效率和应用质量。通过阅读这份文档,开发者可以掌握如何有效地利用Spring的各种模块进行应用程序的构建和维护。
16.11. Handling exceptions ...................................................................................477
HandlerExceptionResolver ............................................................................477
@ExceptionHandler ......................................................................................478
16.12. Convention over configuration support ........................................................478
The Controller ControllerClassNameHandlerMapping ....................................479
The Model ModelMap (ModelAndView) .......................................................480
The View - RequestToViewNameTranslator ..................................................481
16.13. ETag support ..............................................................................................483
16.14. Configuring Spring MVC ............................................................................483
Enabling MVC Java Config or the MVC XML Namespace .............................484
Customizing the Provided Configuration ........................................................485
Configuring Interceptors ...............................................................................486
Configuring View Controllers .......................................................................486
Configuring Serving of Resources .................................................................487
mvc:default-servlet-handler ...........................................................................489
More Spring Web MVC Resources ................................................................490
Advanced Customizations with MVC Java Config ..........................................490
Advanced Customizations with the MVC Namespace .....................................491
17. View technologies ...................................................................................................493
17.1. Introduction .................................................................................................493
17.2. JSP & JSTL .................................................................................................493
View resolvers .............................................................................................493
'Plain-old' JSPs versus JSTL ..........................................................................494
Additional tags facilitating development ........................................................494
Using Spring's form tag library ......................................................................494
Configuration .......................................................................................494
The form tag ........................................................................................495
The input tag ........................................................................................496
The checkbox tag ..................................................................................496
The checkboxes tag ..............................................................................498
The radiobutton tag ...............................................................................498
The radiobuttons tag .............................................................................499
The password tag ..................................................................................499
The select tag .......................................................................................499
The option tag ......................................................................................500
The options tag .....................................................................................500
The textarea tag ....................................................................................501
The hidden tag ......................................................................................501
The errors tag .......................................................................................502
HTTP Method Conversion ....................................................................504
HTML5 Tags .......................................................................................504
17.3. Tiles ............................................................................................................505
Dependencies ...............................................................................................505
How to integrate Tiles ...................................................................................505
UrlBasedViewResolver .........................................................................506
Spring Framework
3.1 Reference Documentation xvi
ResourceBundleViewResolver ..............................................................506
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................506
17.4. Velocity & FreeMarker .................................................................................507
Dependencies ...............................................................................................507
Context configuration ...................................................................................507
Creating templates ........................................................................................508
Advanced configuration ................................................................................508
velocity.properties ................................................................................509
FreeMarker ..........................................................................................509
Bind support and form handling .....................................................................509
The bind macros ...................................................................................510
Simple binding .....................................................................................510
Form input generation macros ...............................................................511
HTML escaping and XHTML compliance .............................................515
17.5. XSLT ..........................................................................................................516
My First Words ............................................................................................516
Bean definitions ...................................................................................516
Standard MVC controller code ..............................................................516
Convert the model data to XML ............................................................517
Defining the view properties ..................................................................518
Document transformation ......................................................................518
Summary .....................................................................................................518
17.6. Document views (PDF/Excel) .......................................................................519
Introduction .................................................................................................519
Configuration and setup ................................................................................519
Document view definitions ....................................................................519
Controller code .....................................................................................520
Subclassing for Excel views ..................................................................520
Subclassing for PDF views ....................................................................521
17.7. JasperReports ...............................................................................................522
Dependencies ...............................................................................................522
Configuration ...............................................................................................522
Configuring the ViewResolver ..............................................................523
Configuring the Views ..........................................................................523
About Report Files ...............................................................................523
Using JasperReportsMultiFormatView ...................................................524
Populating the ModelAndView ......................................................................525
Working with Sub-Reports ............................................................................525
Configuring Sub-Report Files ................................................................526
Configuring Sub-Report Data Sources ...................................................526
Configuring Exporter Parameters ...................................................................527
17.8. Feed Views ..................................................................................................527
17.9. XML Marshalling View ................................................................................528
17.10. JSON Mapping View ..................................................................................528
18. Integrating with other web frameworks .....................................................................530
Spring Framework
3.1 Reference Documentation xvii
18.1. Introduction .................................................................................................530
18.2. Common configuration .................................................................................531
18.3. JavaServer Faces 1.1 and 1.2 .........................................................................532
DelegatingVariableResolver (JSF 1.1/1.2) ......................................................532
SpringBeanVariableResolver (JSF 1.1/1.2) .....................................................533
SpringBeanFacesELResolver (JSF 1.2+) ........................................................533
FacesContextUtils ........................................................................................534
18.4. Apache Struts 1.x and 2.x .............................................................................534
ContextLoaderPlugin ....................................................................................535
DelegatingRequestProcessor .................................................................536
DelegatingActionProxy .........................................................................536
ActionSupport Classes ..................................................................................537
18.5. WebWork 2.x ...............................................................................................537
18.6. Tapestry 3.x and 4.x .....................................................................................538
Injecting Spring-managed beans ....................................................................539
Dependency Injecting Spring Beans into Tapestry pages .........................540
Component definition files ....................................................................541
Adding abstract accessors ......................................................................542
Dependency Injecting Spring Beans into Tapestry pages - Tapestry 4.x style
.............................................................................................................544
18.7. Further Resources .........................................................................................545
19. Portlet MVC Framework .........................................................................................546
19.1. Introduction .................................................................................................546
Controllers - The C in MVC ..........................................................................547
Views - The V in MVC .................................................................................547
Web-scoped beans ........................................................................................548
19.2. The DispatcherPortlet ...................................................................................548
19.3. The ViewRendererServlet .............................................................................550
19.4. Controllers ...................................................................................................551
AbstractController and PortletContentGenerator .............................................551
Other simple controllers ................................................................................553
Command Controllers ...................................................................................553
PortletWrappingController ............................................................................554
19.5. Handler mappings ........................................................................................554
PortletModeHandlerMapping ........................................................................555
ParameterHandlerMapping ............................................................................556
PortletModeParameterHandlerMapping .........................................................556
Adding HandlerInterceptors ..........................................................................557
HandlerInterceptorAdapter ............................................................................557
ParameterMappingInterceptor .......................................................................557
19.6. Views and resolving them .............................................................................558
19.7. Multipart (file upload) support ......................................................................558
Using the PortletMultipartResolver ................................................................559
Handling a file upload in a form ....................................................................559
19.8. Handling exceptions .....................................................................................562
Spring Framework
3.1 Reference Documentation xviii
19.9. Annotation-based controller configuration .....................................................563
Setting up the dispatcher for annotation support ..............................................563
Defining a controller with @Controller ..........................................................563
Mapping requests with @RequestMapping .....................................................564
Supported handler method arguments ............................................................565
Binding request parameters to method parameters with @RequestParam ..........567
Providing a link to data from the model with @ModelAttribute .......................568
Specifying attributes to store in a Session with @SessionAttributes .................568
Customizing WebDataBinder initialization .....................................................569
Customizing data binding with @InitBinder ...........................................569
Configuring a custom WebBindingInitializer ..........................................569
19.10. Portlet application deployment ....................................................................570
VI. Integration ......................................................................................................................571
20. Remoting and web services using Spring ..................................................................572
20.1. Introduction .................................................................................................572
20.2. Exposing services using RMI ........................................................................573
Exporting the service using the RmiServiceExporter .......................................573
Linking in the service at the client .................................................................574
20.3. Using Hessian or Burlap to remotely call services via HTTP ...........................575
Wiring up the DispatcherServlet for Hessian and co. .......................................575
Exposing your beans by using the HessianServiceExporter ..............................575
Linking in the service on the client ................................................................576
Using Burlap ................................................................................................576
Applying HTTP basic authentication to a service exposed through Hessian or
Burlap ..........................................................................................................577
20.4. Exposing services using HTTP invokers ........................................................577
Exposing the service object ...........................................................................577
Linking in the service at the client .................................................................578
20.5. Web services ................................................................................................579
Exposing servlet-based web services using JAX-RPC .....................................580
Accessing web services using JAX-RPC ........................................................580
Registering JAX-RPC Bean Mappings ...........................................................582
Registering your own JAX-RPC Handler .......................................................583
Exposing servlet-based web services using JAX-WS ......................................583
Exporting standalone web services using JAX-WS .........................................584
Exporting web services using the JAX-WS RI's Spring support .......................585
Accessing web services using JAX-WS ..........................................................585
20.6. JMS .............................................................................................................586
Server-side configuration ..............................................................................587
Client-side configuration ...............................................................................588
20.7. Auto-detection is not implemented for remote interfaces .................................589
20.8. Considerations when choosing a technology ...................................................589
20.9. Accessing RESTful services on the Client ......................................................590
RestTemplate ...............................................................................................590
Working with the URI ..........................................................................592
Spring Framework
3.1 Reference Documentation xix
Dealing with request and response headers .............................................593
HTTP Message Conversion ...........................................................................593
StringHttpMessageConverter .................................................................594
FormHttpMessageConverter ..................................................................594
ByteArrayHttpMessageConverter ..........................................................594
MarshallingHttpMessageConverter ........................................................594
MappingJacksonHttpMessageConverter .................................................595
SourceHttpMessageConverter ...............................................................595
BufferedImageHttpMessageConverter ...................................................595
21. Enterprise JavaBeans (EJB) integration ....................................................................596
21.1. Introduction .................................................................................................596
21.2. Accessing EJBs ............................................................................................596
Concepts ......................................................................................................596
Accessing local SLSBs .................................................................................597
Accessing remote SLSBs ..............................................................................598
Accessing EJB 2.x SLSBs versus EJB 3 SLSBs ..............................................599
21.3. Using Spring's EJB implementation support classes ........................................599
EJB 2.x base classes .....................................................................................599
EJB 3 injection interceptor ............................................................................601
22. JMS (Java Message Service) ....................................................................................603
22.1. Introduction .................................................................................................603
22.2. Using Spring JMS ........................................................................................603
JmsTemplate ................................................................................................603
Connections .................................................................................................604
Caching Messaging Resources ...............................................................605
SingleConnectionFactory ......................................................................605
CachingConnectionFactory ...................................................................605
Destination Management ...............................................................................605
Message Listener Containers .........................................................................606
SimpleMessageListenerContainer ..........................................................607
DefaultMessageListenerContainer .........................................................607
Transaction management ...............................................................................607
22.3. Sending a Message .......................................................................................608
Using Message Converters ............................................................................609
SessionCallback and ProducerCallback ..........................................................610
22.4. Receiving a message .....................................................................................610
Synchronous Reception .................................................................................610
Asynchronous Reception - Message-Driven POJOs ........................................610
The SessionAwareMessageListener interface .................................................611
The MessageListenerAdapter ........................................................................611
Processing messages within transactions ........................................................613
22.5. Support for JCA Message Endpoints ..............................................................614
22.6. JMS Namespace Support ..............................................................................616
23. JMX .......................................................................................................................621
23.1. Introduction .................................................................................................621
Spring Framework
3.1 Reference Documentation xx
剩余839页未读,继续阅读
120 浏览量
2022-05-09 上传
2012-04-28 上传
2023-03-05 上传
2023-03-05 上传
2023-03-06 上传
2023-03-06 上传
2023-03-06 上传
风里来云里去
- 粉丝: 9
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 构建基于Django和Stripe的SaaS应用教程
- Symfony2框架打造的RESTful问答系统icare-server
- 蓝桥杯Python试题解析与答案题库
- Go语言实现NWA到WAV文件格式转换工具
- 基于Django的医患管理系统应用
- Jenkins工作流插件开发指南:支持Workflow Python模块
- Java红酒网站项目源码解析与系统开源介绍
- Underworld Exporter资产定义文件详解
- Java版Crash Bandicoot资源库:逆向工程与源码分享
- Spring Boot Starter 自动IP计数功能实现指南
- 我的世界牛顿物理学模组深入解析
- STM32单片机工程创建详解与模板应用
- GDG堪萨斯城代码实验室:离子与火力基地示例应用
- Android Capstone项目:实现Potlatch服务器与OAuth2.0认证
- Cbit类:简化计算封装与异步任务处理
- Java8兼容的FullContact API Java客户端库介绍
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功