spring-framework-reference 3.1
Table of Contents I. Overview of Spring Framework ..............................................................................................1 1. Introduction to Spring Framework ..................................................................................2 1.1. Dependency Injection and Inversion of Control ....................................................2 1.2. Modules ............................................................................................................3 Core Container .................................................................................................3 Data Access/Integration ....................................................................................3 Web .................................................................................................................4 AOP and Instrumentation ..................................................................................4 Test .................................................................................................................4 1.3. Usage scenarios .................................................................................................5 Dependency Management and Naming Conventions ...........................................6 Spring Dependencies and Depending on Spring ..........................................8 Maven Dependency Management ..............................................................8 Ivy Dependency Management .................................................................10 Logging .........................................................................................................10 Not Using Commons Logging .................................................................11 Using SLF4J ..........................................................................................11 Using Log4J ...........................................................................................13 II. What's New in Spring 3 ......................................................................................................15 2. New Features and Enhancements in Spring 3.0 .............................................................16 2.1. Java 5 ..............................................................................................................16 2.2. Improved documentation ..................................................................................16 2.3. New articles and tutorials ..................................................................................16 2.4. New module organization and build system .......................................................17 2.5. Overview of new features .................................................................................18 Core APIs updated for Java 5 ..........................................................................19 Spring Expression Language ...........................................................................19 The Inversion of Control (IoC) container ..........................................................20 Java based bean metadata ........................................................................20 Defining bean metadata within components ..............................................21 General purpose type conversion system and field formatting system .................21 The Data Tier .................................................................................................21 The Web Tier .................................................................................................22 Comprehensive REST support .................................................................22 @MVC additions ...................................................................................22 Declarative model validation ...........................................................................22 Early support for Java EE 6 .............................................................................22 Support for embedded databases ......................................................................22 3. New Features and Enhancements in Spring 3.1 .............................................................23 3.1. Overview of new features .................................................................................23 Spring Framework 3.1 Reference Documentation ii Cache Abstraction ..........................................................................................23 Bean Definition Profiles ..................................................................................23 Environment Abstraction ................................................................................23 PropertySource Abstraction .............................................................................23 Code equivalents for Spring's XML namespaces ...............................................24 Builder-style APIs for code-based Hibernate configuration ................................24 TestContext framework support for @Configuration classes and bean definition profiles ..........................................................................................................24 c: namespace for more concise constructor injection .........................................24 Support for injection against non-standard JavaBeans setters .............................24 Support for Servlet 3 code-based configuration of Servlet Container ..................25 Support for Servlet 3 MultipartResolver ...........................................................25 JPA EntityManagerFactory bootstrapping without persistence.xml ....................25 New HandlerMethod-based Support Classes For Annotated Controller Processing .......................................................................................................................25 Consumes and Produces @RequestMapping Conditions ...................................26 Working With URI Template Variables In Controller Methods ..........................26 Validation For @RequestBody Method Arguments ...........................................27 III. Core Technologies ............................................................................................................28 4. The IoC container .......................................................................................................29 4.1. Introduction to the Spring IoC container and beans .............................................29 4.2. Container overview ..........................................................................................29 Configuration metadata ...................................................................................30 Instantiating a container ..................................................................................31 Composing XML-based configuration metadata .......................................33 Using the container .........................................................................................33 4.3. Bean overview .................................................................................................34 Naming beans .................................................................................................35 Aliasing a bean outside the bean definition ...............................................36 Instantiating beans ..........................................................................................37 Instantiation with a constructor ................................................................37 Instantiation with a static factory method .................................................38 Instantiation using an instance factory method ..........................................38 4.4. Dependencies ...................................................................................................40 Dependency injection ......................................................................................40 Constructor-based dependency injection ...................................................40 Setter-based dependency injection ...........................................................42 Dependency resolution process ................................................................43 Examples of dependency injection ...........................................................45 Dependencies and configuration in detail .........................................................47 Straight values (primitives, Strings, and so on) .........................................47 References to other beans (collaborators) .................................................48 Inner beans .............................................................................................49 Collections .............................................................................................50 Null and empty string values ...................................................................52 Spring Framework 3.1 Reference Documentation iii XML shortcut with the p-namespace ........................................................53 XML shortcut with the c-namespace ........................................................54 Compound property names ......................................................................55 Using depends-on ...........................................................................................55 Lazy-initialized beans .....................................................................................56 Autowiring collaborators .................................................................................56 Limitations and disadvantages of autowiring ............................................58 Excluding a bean from autowiring ...........................................................58 Method injection ............................................................................................59 Lookup method injection .........................................................................60 Arbitrary method replacement .................................................................61 4.5. Bean scopes .....................................................................................................62 The singleton scope ........................................................................................63 The prototype scope ........................................................................................64 Singleton beans with prototype-bean dependencies ...........................................65 Request, session, and global session scopes ......................................................65 Initial web configuration .........................................................................65 Request scope .........................................................................................66 Session scope .........................................................................................66 Global session scope ...............................................................................67 Scoped beans as dependencies .................................................................67 Custom scopes ...............................................................................................69 Creating a custom scope ..........................................................................69 Using a custom scope ..............................................................................70 4.6. Customizing the nature of a bean .......................................................................71 Lifecycle callbacks .........................................................................................72 Initialization callbacks ............................................................................72 Destruction callbacks ..............................................................................73 Default initialization and destroy methods ................................................73 Combining lifecycle mechanisms ............................................................75 Startup and shutdown callbacks ...............................................................75 Shutting down the Spring IoC container gracefully in non-web applications 77 ApplicationContextAware and BeanNameAware ..............................................78 Other Aware interfaces ...................................................................................78 4.7. Bean definition inheritance ...............................................................................80 4.8. Container Extension Points ...............................................................................82 Customizing beans using a BeanPostProcessor .................................................82 Example: Hello World, BeanPostProcessor-style ......................................83 Example: The RequiredAnnotationBeanPostProcessor ..............................84 Customizing configuration metadata with a BeanFactoryPostProcessor ..............85 Example: the PropertyPlaceholderConfigurer ...........................................86 Example: the PropertyOverrideConfigurer ...............................................87 Customizing instantiation logic with a FactoryBean ..........................................88 4.9. Annotation-based container configuration ..........................................................89 @Required .....................................................................................................90 Spring Framework 3.1 Reference Documentation iv @Autowired and @Inject ................................................................................91 Fine-tuning annotation-based autowiring with qualifiers ...................................94 CustomAutowireConfigurer ............................................................................99 @Resource ................................................................................................... 100 @PostConstruct and @PreDestroy ................................................................. 101 4.10. Classpath scanning and managed components ................................................ 101 @Component and further stereotype annotations ............................................ 102 Automatically detecting classes and registering bean definitions ...................... 102 Using filters to customize scanning ................................................................ 103 Defining bean metadata within components .................................................... 104 Naming autodetected components .................................................................. 106 Providing a scope for autodetected components .............................................. 107 Providing qualifier metadata with annotations ................................................ 107 4.11. Using JSR 330 standard annotations .............................................................. 108 Dependency Injection with @Inject and @Named .......................................... 109 @Named: a standard equivalent to the @Component annotation ...................... 109 Limitations of the standard approach .............................................................. 110 4.12. Java-based container configuration ................................................................ 111 Basic concepts: @Configuration and @Bean .................................................. 111 Instantiating the Spring container using AnnotationConfigApplicationContext . 111 Simple construction .............................................................................. 112 Building the container programmatically using register(Class<?>...) ........ 112 Enabling component scanning with scan(String...) .................................. 112 Support for web applications with AnnotationConfigWebApplicationContext ............................................................................................................. 113 Composing Java-based configurations ............................................................ 114 Using the @Import annotation ............................................................... 114 Combining Java and XML configuration ................................................ 117 Using the @Bean annotation ......................................................................... 119 Declaring a bean ................................................................................... 119 Injecting dependencies .......................................................................... 120 Receiving lifecycle callbacks ................................................................. 120 Specifying bean scope ........................................................................... 121 Customizing bean naming ..................................................................... 123 Bean aliasing ........................................................................................ 123 Further information about how Java-based configuration works internally ........ 123 4.13. Registering a LoadTimeWeaver .................................................................... 124 4.14. Additional Capabilities of the ApplicationContext .......................................... 125 Internationalization using MessageSource ...................................................... 125 Standard and Custom Events ......................................................................... 128 Convenient access to low-level resources ....................................................... 131 Convenient ApplicationContext instantiation for web applications ................... 132 Deploying a Spring ApplicationContext as a J2EE RAR file ............................ 133 4.15. The BeanFactory .......................................................................................... 133 BeanFactory or ApplicationContext? ............................................................. 134 Spring Framework 3.1 Reference Documentation v Glue code and the evil singleton .................................................................... 135 5. Resources ................................................................................................................. 137 5.1. Introduction ................................................................................................... 137 5.2. The Resource interface ................................................................................... 137 5.3. Built-in Resource implementations .................................................................. 138 UrlResource ................................................................................................. 138 ClassPathResource ....................................................................................... 139 FileSystemResource ..................................................................................... 139 ServletContextResource ................................................................................ 139 InputStreamResource .................................................................................... 139 ByteArrayResource ...................................................................................... 140 5.4. The ResourceLoader ....................................................................................... 140 5.5. The ResourceLoaderAware interface ............................................................... 141 5.6. Resources as dependencies ............................................................................. 142 5.7. Application contexts and Resource paths ......................................................... 142 Constructing application contexts .................................................................. 142 Constructing ClassPathXmlApplicationContext instances - shortcuts ....... 143 Wildcards in application context constructor resource paths ............................ 144 Ant-style Patterns ................................................................................. 144 The classpath*: prefix ........................................................................... 145 Other notes relating to wildcards ............................................................ 145 FileSystemResource caveats .......................................................................... 146 6. Validation, Data Binding, and Type Conversion .......................................................... 148 6.1. Introduction ................................................................................................... 148 6.2. Validation using Spring's Validator interface .................................................... 148 6.3. Resolving codes to error messages .................................................................. 150 6.4. Bean manipulation and the BeanWrapper ........................................................ 150 Setting and getting basic and nested properties ............................................... 151 Built-in PropertyEditor implementations ........................................................ 152 Registering additional custom PropertyEditors ....................................... 155 6.5. Spring 3 Type Conversion .............................................................................. 158 Converter SPI ............................................................................................... 158 ConverterFactory .......................................................................................... 159 GenericConverter ......................................................................................... 160 ConditionalGenericConverter ................................................................ 160 ConversionService API ................................................................................. 161 Configuring a ConversionService .................................................................. 161 Using a ConversionService programatically ................................................... 162 6.6. Spring 3 Field Formatting ............................................................................... 162 Formatter SPI ............................................................................................... 163 Annotation-driven Formatting ....................................................................... 164 Format Annotation API ......................................................................... 165 FormatterRegistry SPI .................................................................................. 166 FormatterRegistrar SPI ................................................................................. 166 Configuring Formatting in Spring MVC ......................................................... 167 Spring Framework 3.1 Reference Documentation vi 6.7. Spring 3 Validation ........................................................................................ 168 Overview of the JSR-303 Bean Validation API ............................................... 168 Configuring a Bean Validation Implementation .............................................. 169 Injecting a Validator ............................................................................. 169 Configuring Custom Constraints ............................................................ 170 Additional Configuration Options .......................................................... 170 Configuring a DataBinder ............................................................................. 170 Spring MVC 3 Validation ............................................................................. 171 Triggering @Controller Input Validation ............................................... 171 Configuring a Validator for use by Spring MVC ..................................... 171
- yl2775743252013-08-14资源不错,可惜是英文的看不太懂
- zc93cs2015-08-28还不错,很完整
- lovewormcn2012-09-09非扫描版的,内容完整!
- 粉丝: 34
- 资源: 269
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助