img
Figure 4-1. Dependency Pull via JNDI lookup
Spring also offers Dependency Pull as a mechanism for retrieving the components that the
framework manages; you saw this in action in Chapter 2. Listing 4-1 shows a typical Dependency Pull
lookup in a Spring-based application.
Listing 4-1. Dependency Pull in Spring
public static void main(String[] args) throws Exception {
// get the bean factory
BeanFactory factory = getBeanFactory();
MessageRenderer mr = (MessageRenderer) factory.getBean("renderer");
mr.render();
}
Not only is this kind of IoC prevalent in JEE-based applications (using EJB 2.1 or prior versions),
which make extensive use of JNDI lookups to obtain dependencies from a registry, but it is also pivotal to
working with Spring in many environments.
Contextualized Dependency Lookup
Contextualized Dependency Lookup (CDL) is similar, in some respects, to Dependency Pull, but in CDL,
lookup is performed against the container that is managing the resource, not from some central registry,
and it is usually performed at some set point. Figure 4-2 shows the CDL mechanism.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home