Topic 5
■■■
Spring Configuration in Detail
In the previous chapter, we took a detailed look at the concept of Inversion of Control (IoC) and how it
fits into the Spring Framework. However, as we said at the end of the previous chapter, we have really
only scratched the surface of what the Spring core can do.
Spring provides a wide array of services that supplement and extend the basic IoC capabilities. A
number of projects provide IoC containers, but none so far provides the same comprehensive feature set
Spring provides. In this chapter, we are going to look in detail at some additional IoC-related features of-
fered in Spring along with other functionality offered by the Spring core. In addition, we will look at using
Java classes when configuring Spring's ApplicationContext, together with some new features that exist in
3.0 and 3.1 for more advanced configuration options. Specifically, we will be looking at the following:
Managing the bean life cycle: So far, all the beans you have seen have been fairly
·
simple and completely decoupled from the Spring container. In this section, we
look at some strategies you can employ to enable your beans to receive
notifications from the Spring container at various points throughout their life
cycle. You can do this either by implementing specific interfaces laid out by
Spring, by specifying methods that Spring can call via reflection, or by using JSR-
250 JavaBeans life-cycle annotations.
Making your beans "Spring aware": In some cases, you want a bean to be able to
·
interact with the ApplicationContext that configured it. For this reason, Spring
offers two interfaces, BeanNameAware and ApplicationContextAware, that allow your
bean to obtain its assigned name (i.e., the id or name attribute in the <bean> tag,
with the id attribute having higher preference) and reference its
ApplicationContext, respectively. This section of the chapter looks at
implementing these interfaces and gives some practical considerations for using
them in your application.
Using FactoryBeans: As its name implies, the FactoryBean interface is intended to
·
be implemented by any bean that acts as a factory for other beans. The
FactoryBean interface provides a mechanism by which you can easily integrate
your own factories with the Spring BeanFactory.
Working with JavaBeans PropertyEditors: The PropertyEditor interface is a
·
standard interface provided in the java.beans package. PropertyEditors are used
to convert property values to and from String representations. Spring uses
PropertyEditors extensively, mainly to read values specified in the BeanFactory
configuration and convert them into the correct types. In this section of the
chapter, we discuss the set of PropertyEditors supplied with Spring and how you
can use them within your application. We also take a look at implementing custom
PropertyEditors.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home