spring-framework-reference-4.1.1
Spring Dependencies and Depending on Spring ......................................... 11 Maven Dependency Management ............................................................. 11 Maven "Bill Of Materials" Dependency ....................................................... 12 Gradle Dependency Management ............................................................. 12 Ivy Dependency Management ................................................................... 13 Distribution Zip Files ................................................................................. 13 Logging ............................................................................................................ 13 Not Using Commons Logging ................................................................... 14 Using SLF4J ............................................................................................ 14 Using Log4J ............................................................................................. 15 II. What’s New in Spring Framework 4.x .................................................................................... 17 3. New Features and Enhancements in Spring Framework 4.0 ............................................ 18 3.1. Improved Getting Started Experience .................................................................. 18 3.2. Removed Deprecated Packages and Methods .................................................... 18 3.3. Java 8 (as well as 6 and 7) ............................................................................... 18 3.4. Java EE 6 and 7 ............................................................................................... 19 3.5. Groovy Bean Definition DSL .............................................................................. 19 3.6. Core Container Improvements ............................................................................ 19 3.7. General Web Improvements ............................................................................... 20 3.8. WebSocket, SockJS, and STOMP Messaging ..................................................... 20 3.9. Testing Improvements ........................................................................................ 21 4. New Features and Enhancements in Spring Framework 4.1 ............................................ 22 4.1. JMS Improvements ............................................................................................ 22 4.2. Caching Improvements ...................................................................................... 22 4.3. Web Improvements ............................................................................................ 23 4.4. WebSocket Messaging Improvements ................................................................. 24 4.5. Testing Improvements ........................................................................................ 24 5. New Features and Enhancements in Spring Framework 4.2 ............................................ 26 5.1. Core Container Improvements ............................................................................ 26 5.2. Data Access Improvements ................................................................................ 27 5.3. JMS Improvements ............................................................................................ 28 5.4. Web Improvements ............................................................................................ 28 5.5. WebSocket Messaging Improvements ................................................................. 29 5.6. Testing Improvements ........................................................................................ 29 Configuration metadata ..................................................................................... 34 Instantiating a container .................................................................................... 35 Composing XML-based configuration metadata .......................................... 36 Using the container .......................................................................................... 37 6.3. Bean overview ................................................................................................... 37 Naming beans .................................................................................................. 38 Aliasing a bean outside the bean definition ................................................ 39 Instantiating beans ........................................................................................... 40 Instantiation with a constructor .................................................................. 40 Instantiation with a static factory method .................................................... 41 Instantiation using an instance factory method ........................................... 41 6.4. Dependencies ................................................................................................... 42 Dependency Injection ....................................................................................... 42 Constructor-based dependency injection .................................................... 43 Setter-based dependency injection ............................................................ 45 Dependency resolution process ................................................................. 46 Examples of dependency injection ............................................................. 47 Dependencies and configuration in detail ........................................................... 49 Straight values (primitives, Strings, and so on) ........................................... 49 References to other beans (collaborators) .................................................. 50 Inner beans .............................................................................................. 51 Collections ............................................................................................... 51 Null and empty string values ..................................................................... 54 XML shortcut with the p-namespace .......................................................... 54 XML shortcut with the c-namespace .......................................................... 55 Compound property names ....................................................................... 56 Using depends-on ............................................................................................ 57 Lazy-initialized beans ....................................................................................... 57 Autowiring collaborators .................................................................................... 58 Limitations and disadvantages of autowiring ............................................... 59 Excluding a bean from autowiring .............................................................. 59 Method injection ............................................................................................... 60 Lookup method injection ........................................................................... 61 Arbitrary method replacement ................................................................... 62 6.5. Bean scopes ..................................................................................................... 63 The singleton scope ......................................................................................... 64 The prototype scope ......................................................................................... 65 Singleton beans with prototype-bean dependencies ............................................ 66 Request, session, and global session scopes .................................................... 66 Initial web configuration ............................................................................ 67 Request scope ......................................................................................... 67 Session scope .......................................................................................... 68 Global session scope ............................................................................... 68 Application scope ..................................................................................... 68 Scoped beans as dependencies ................................................................ 68 Custom scopes ................................................................................................ 71 and BeanNameAware ................................................. 79 Other Aware interfaces ..................................................................................... 79 6.7. Bean definition inheritance ................................................................................. 81 6.8. Container Extension Points ................................................................................ 82 Customizing beans using a BeanPostProcessor ................................................. 82 Example: Hello World, BeanPostProcessor-style ........................................ 84 Example: The RequiredAnnotationBeanPostProcessor ............................... 85 Customizing configuration metadata with a BeanFactoryPostProcessor ................ 85 Example: the Class name substitution PropertyPlaceholderConfigurer .......... 86 Example: the PropertyOverrideConfigurer .................................................. 88 Customizing instantiation logic with a FactoryBean ............................................. 89 6.9. Annotation-based container configuration ............................................................ 89 @Required ....................................................................................................... 90 @Autowired ..................................................................................................... 91 Fine-tuning annotation-based autowiring with @Primary ..................................... 94 Fine-tuning annotation-based autowiring with qualifiers ....................................... 95 Using generics as autowiring qualifiers ............................................................ 100 CustomAutowireConfigurer .............................................................................. 100 @Resource .................................................................................................... 101 @PostConstruct and @PreDestroy .................................................................. 102 6.10. Classpath scanning and managed components ................................................ 102 @Component and further stereotype annotations ............................................. 103 Meta-annotations ............................................................................................ 103 Automatically detecting classes and registering bean definitions ........................ 104 Using filters to customize scanning .................................................................. 105 Defining bean metadata within components ..................................................... 106 Naming autodetected components ................................................................... 109 Providing a scope for autodetected components ............................................... 110 Providing qualifier metadata with annotations ................................................... 111 6.11. Using JSR 330 Standard Annotations ............................................................. 111 Dependency Injection with @Inject and @Named ............................................. 112 @Named: a standard equivalent to the @Component annotation ....................... 112 Limitations of the standard approach ............................................................... 113 6.12. Java-based container configuration ................................................................. 114 Basic concepts: @Bean and @Configuration ................................................... 114 Instantiating the Spring container using AnnotationConfigApplicationContext ....... 115 Simple construction ................................................................................ 116 Building the container programmatically using register(Class<?>…) ........... 116 Enabling component scanning with scan(String…) .................................... 116 bean scope ............................................................................ 121 Customizing bean naming ....................................................................... 122 Bean aliasing ......................................................................................... 122 Bean description ..................................................................................... 122 Using the @Configuration annotation ............................................................... 122 Injecting inter-bean dependencies ............................................................ 122 Lookup method injection ......................................................................... 123 Further information about how Java-based configuration works internally .... 124 Composing Java-based configurations ............................................................. 125 Using the @Import annotation ................................................................. 125 Conditionally include @Configuration classes or @Bean methods .............. 129 Combining Java and XML configuration ................................................... 129 6.13. Environment abstraction ................................................................................. 131 Bean definition profiles ................................................................................... 132 @Profile ................................................................................................. 132 XML bean definition profiles ............................................................................ 134 Activating a profile .................................................................................. 135 Default profile ......................................................................................... 135 PropertySource abstraction ............................................................................. 136 @PropertySource ........................................................................................... 137 Placeholder resolution in statements ................................................................ 138 6.14. Registering a LoadTimeWeaver ...................................................................... 138 6.15. Additional Capabilities of the ApplicationContext .............................................. 138 Internationalization using MessageSource ........................................................ 139 Standard and Custom Events .......................................................................... 141 Annotation-based Event Listeners ............................................................ 144 Generic Events ....................................................................................... 146 Convenient access to low-level resources ........................................................ 147 Convenient ApplicationContext instantiation for web applications ....................... 147 Deploying a Spring ApplicationContext as a Java EE RAR file ........................... 148 6.16. The BeanFactory ........................................................................................... 149 BeanFactory or ApplicationContext? ................................................................ 149 Glue code and the evil singleton ..................................................................... 150 7. Resources .................................................................................................................. 151 7.1. Introduction ..................................................................................................... 151 7.2. The Resource interface .................................................................................... 151 7.3. Built-in Resource implementations .................................................................... 152 UrlResource ................................................................................................... 152 ClassPathResource ........................................................................................ 152 FileSystemResource ....................................................................................... 153 ServletContextResource .................................................................................. 153 InputStreamResource ..................................................................................... 153 ByteArrayResource ......................................................................................... 153 7.4. The ResourceLoader ....................................................................................... 153 ...........
- 粉丝: 4
- 资源: 44
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助