Java Reference
In-Depth Information
The Spring Framework provides a comprehensive set of classes for retrieving JNDI
bound objects from all different application servers. The JndiObjectFactoryBean is the
most widely used service locator class in the Spring Framework. It is a factory bean and
hence implements the FactoryBean interface. A factory bean is an object factory within
the Spring bean factory. Hence, a factory bean is treated differently from a normal bean
by the Spring IOC container. It is configured in the same manner as an ordinary bean,
but Spring will not return a new instance of JndiObjectFactoryBean . Instead, the object it
exposes for injection is always the one that it creates or retrieves. In the case of
JndiObjectFactoryBean , this is made possible by the getObject method that returns the
object retrieved from the JNDI. Thus, this service locator implementation can be used to
look up and inject any kind of JNDI object. Since JndiObjectFactoryBean inherits from the
JndiAccessor class, it easy to configure various JNDI-related properties. Figure 4-2 shows
the Spring JNDI class diagram.
Figure 4-2. Class diagram: Service locator
Remote EJB 2. x Lookup
I will now put the JndiObjectFactoryBean to use. In Listing 3-27, I combined the page con-
troller with the business delegate but deliberately did not show the code for the sake of
simplicity. Listing 4-2 shows the business delegate implementation class. I will cover
business delegates in detail later in this chapter. So, the sole intention of this business
delegate listing here is to highlight how it is related to the service locator. As shown in
Listing 4-2, the business delegate is completely decoupled from the service locator. The
JndiObjectFactoryBean service locator works transparently with the Spring container to
Search WWH ::

Custom Search