O'Reilly logo

Harnessing Hibernate by James Elliott, Ryan Fowler, Timothy M. O'Brien

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an Application Context

When we introduced Spring we discussed how it would assume responsibility for creating and connecting the components in our application. For Spring to do this, we need to tell it about the various components (which Spring calls beans) in our system and how they are connected to each other. We do this using an XML document that describes the class of each bean, assigns it an ID, and establishes its relationships to other beans. Why the ID? In this context, an ID is a unique logical name for the bean, which is what you use to express relationships with other beans, and to request beans at runtime. In our example Spring configuration file we use logical names such as artistDao and albumDao. Each ID refers to a single component defined in the file.

This XML document is then used by Spring to create an ApplicationContext object from which we can retrieve our components by name. Figure 13-2 is a diagram of our application’s ApplicationContext.

Our Spring application context

Figure 13-2. Our Spring application context

From Figure 13-2 you can see that we have three test components that are connected to three DAO objects, and the DAO objects all have a reference to the sessionFactory object which is responsible for creating a Hibernate Session object and connecting to the database. This application is described by the Spring configuration file shown in Example 13-8, which you should name

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required