Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Spring Reference

Spring Reference

Ratings: (0)|Views: 28 |Likes:
Published by api-3836483

More info:

Published by: api-3836483 on Oct 18, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Reference Documentation
Version 1.2.7
(Work in progress)

Copyright (c) 2004-2006 Rod Johnson, Juergen Hoeller, Alef Arendsen, Colin Sampaleanu,
Rob Harrop, Thomas Risberg, Darren Davison, Dmitriy Kopylenko, Mark Pollack, Thierry
Templier, Erwin Vervaet

Copies of this document may be made for your own use and for distribution to others, provided that you do not
charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether
distributed in print or electronically.

Table of Contents
Preface................................................................................................................................................
1. Introduction..................................................................................................................................
1.1. Overview............................................................................................................................. 1
1.2. Usage scenarios.................................................................................................................... 2
2. Background information...............................................................................................................
2.1. Inversion of Control / Dependency Injection.......................................................................... 5
3. Beans, BeanFactory and the ApplicationContext..........................................................................
3.1. Introduction......................................................................................................................... 6

3.2. BeanFactory and BeanDefinitions - the basics........................................................................ 6 3.2.1. The BeanFactory....................................................................................................... 6 3.2.2. The BeanDefinition................................................................................................... 8 3.2.3. The bean class........................................................................................................... 8 3.2.4. The bean identifiers (id and

name)............................................................................................................................ 10
3.2.5. To singleton or not to singleton.................................................................................. 10
3.3. Properties, collaborators, autowiring and dependency

checking.................................................................................................................................. 11 3.3.1. Setting bean properties and collaborators.................................................................... 11 3.3.2. Constructor Argument Resolution............................................................................... 14 3.3.3. Bean properties and constructor arguments detailed..................................................... 15 3.3.4. Method Injection....................................................................................................... 19 3.3.5. Using depends-on...................................................................................................... 21 3.3.6. Autowiring collaborators............................................................................................ 22 3.3.7. Checking for dependencies......................................................................................... 23

3.4. Customizing the nature of a bean........................................................................................... 23 3.4.1. Lifecycle interfaces................................................................................................... 24 3.4.2. Knowing who you are................................................................................................ 25 3.4.3. FactoryBean.............................................................................................................. 26

3.5. Abstract and child bean definitions........................................................................................ 26
3.6. Interacting with the BeanFactory........................................................................................... 27
3.6.1. Obtaining a FactoryBean, not its product..................................................................... 28
3.7. Customizing beans with BeanPostProcessors......................................................................... 28
3.8. Customizing bean factories with BeanFactoryPostProcessors.................................................. 28

3.8.1. The PropertyPlaceholderConfigurer............................................................................ 29

3.8.2. The PropertyOverrideConfigurer................................................................................ 30 3.9. Registering additional custom PropertyEditors....................................................................... 30 3.10. Using the alias element to add aliases for existing beans....................................................... 31 3.11. Introduction to the ApplicationContext................................................................................ 32 3.12. Added functionality of the

ApplicationContext.................................................................................................................. 32 3.12.1. Using the MessageSource......................................................................................... 32 3.12.2. Propagating events................................................................................................... 33 3.12.3. Low-level resources and the application context........................................................ 34

3.13. Customized behavior in the ApplicationContext................................................................... 35
3.13.1. ApplicationContextAware marker

interface........................................................................................................................ 35 3.13.2. The BeanPostProcessor............................................................................................ 35 3.13.3. The BeanFactoryPostProcessor................................................................................. 35

Spring Framework Version 1.2.7
ii

3.13.4. The PropertyPlaceholderConfigurer.......................................................................... 36 3.14. Registering additional custom PropertyEditors..................................................................... 36 3.15. Setting a bean property or constructor arg from a property

expression............................................................................................................................... 37
3.16. Setting a bean property or constructor arg from a field
value....................................................................................................................................... 38
3.17. Invoking another method and optionally using the return

value. ...................................................................................................................................... 38 3.18. Importing Bean Definitions from One File Into Another....................................................... 39 3.19. Creating an ApplicationContext from a web application........................................................ 40 3.20. Glue code and the evil singleton.......................................................................................... 41

3.20.1. Using SingletonBeanFactoryLocator and
ContextSingletonBeanFactoryLocator............................................................................. 41
4. Abstracting Access to Low-Level Resources..................................................................................
4.1. Overview............................................................................................................................. 43
4.2. The Resource interface......................................................................................................... 43

4.3. Built-in Resource implementations........................................................................................ 44 4.3.1. UrlResource.............................................................................................................. 44 4.3.2. ClassPathResource.................................................................................................... 44 4.3.3. FileSystemResource.................................................................................................. 45 4.3.4. ServletContextResource............................................................................................. 45 4.3.5. InputStreamResource................................................................................................. 45 4.3.6. ByteArrayResource................................................................................................... 45

4.4. The ResourceLoader Interface............................................................................................... 45
4.5. The ResourceLoaderAware interface..................................................................................... 46
4.6. Setting Resources as properties............................................................................................. 46
4.7. Application contexts and Resource paths............................................................................... 47
4.7.1. Constructing application contexts............................................................................... 47
4.7.2. The classpath*: prefix................................................................................................ 47

4.7.3. Unexpected application context handling of FileSystemResource
absolute paths................................................................................................................ 48
5. PropertyEditors, data binding, validation and the BeanWrapper.................................................

5.1. Introduction......................................................................................................................... 50 5.2. Binding data using the DataBinder........................................................................................ 50 5.3. Bean manipulation and the BeanWrapper............................................................................... 50

5.3.1. Setting and getting basic and nested properties............................................................ 51
5.3.2. Built-in PropertyEditors, converting

types............................................................................................................................. 52
5.3.3. Other features worth mentioning................................................................................. 54
5.4. Validation using Spring's Validator interface.......................................................................... 54
5.5. The Errors interface.............................................................................................................. 55
5.6. Resolving codes to error messages......................................................................................... 55

6. Spring AOP: Aspect Oriented Programming with Spring.............................................................

6.1. Concepts.............................................................................................................................. 56 6.1.1. AOP concepts........................................................................................................... 56 6.1.2. Spring AOP capabilities and goals.............................................................................. 57 6.1.3. AOP Proxies in Spring............................................................................................... 58

6.2. Pointcuts in Spring............................................................................................................... 58 6.2.1. Concepts................................................................................................................... 59 6.2.2. Operations on pointcuts............................................................................................. 59 6.2.3. Convenience pointcut implementations....................................................................... 60 6.2.4. Pointcut superclasses................................................................................................. 61

Spring - Java/J2EE Application Framework
Spring Framework Version 1.2.7
iii

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->