System.out.println(bean.getName());
}
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}
}
The previous code is nothing special. Run the example, and you will see the following output:
First name: Clarence - Last name: Ho
This is the output from the toString() method we implemented in the Name class, and you can see
that the first name and last name of the Name object were correctly populated by Spring by using the
configured NamePropertyEditor.
Starting from version 3, Spring introduced the Type Conversion and Field Formatting SPI, which
provide a simpler and well-structured API in performing type conversion and field formatting. It's
especially useful for web application development. Both the Type Conversion SPI and the Field
Formatting API will be discussed in detail in Chapter 14.
More Spring ApplicationContext Configuration
So far, although we are discussing Spring's ApplicationContext, most of the features that we covered were
mainly surrounding the BeanFactory interface wrapped by the ApplicationContext. In Spring, various
implementations of the BeanFactory interface are responsible for bean instantiation, providing
Dependency Injection and life-cycle support for beans managed by Spring. However, as stated, being an
extension of the BeanFactory, ApplicationContext provides other useful functionalities as well.
The main function of the ApplicationContext is to provide a much richer framework on which to
build your applications. An ApplicationContext is much more aware of the beans (compared with
BeanFactory) that you configure within it, and in the case of many of the Spring infrastructure classes
and interfaces, such as BeanFactoryPostProcessor, it interacts with them on your behalf, reducing the
amount of code you need to write in order to use Spring.
The biggest benefit of using ApplicationContext is that it allows you to configure and manage
Spring and Spring-managed resources in a completely declarative way. This means that wherever possible,
Spring provides support classes to load an ApplicationContext into your application auto-matically, thus
removing the need for you to write any code to access the ApplicationContext. In practice, this feature is
currently available only when you are building web applications with Spring, which allows you to initialize
Spring's ApplicationContext in the web application deployment descriptor. When using a stand-alone
application, you can also initialize Spring's ApplicationContext by simple coding.
In addition to providing a model that is focused more on declarative configuration, the
ApplicationContext supports the following additional features:
Internationalization
·
Event publication
·
Resource management and access
·
Additional life-cycle interfaces
·
Improved automatic configuration of infrastructure components
·
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home