25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3<br />

Applying Different Configurations<br />

The <strong>Spring</strong> <strong>Framework</strong> supports different ways to configure its container and this chapter will cover the XML<br />

configuration used previously. Also, you are going to learn how can you accomplish the same configuration<br />

using different mechanisms, such as <strong>Spring</strong> annotations, Java bean configuration class, and the new<br />

GroovyBeanDefinitionReader class.<br />

In the previous chapter, you defined your <strong>Spring</strong> application, My Documents, and you saw how to use a XML<br />

configuration file to inject your implementation of the SearchEngine interface. In this chapter, you will be using<br />

the same XML configuration and you will see what you need to do in order to use all of these new different ways of<br />

configuration.<br />

My Documents XML Configuration<br />

Let’s start by reviewing your current XML configuration (from the My Documents application) context and examine<br />

it (see Listing 3-1).<br />

Listing 3-1. mydocuments-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Listing 3-1 shows how the <strong>Spring</strong> container needs to know something about the classes and its dependencies.<br />

As you saw in the previous chapter, you need to tell it through an XML configuration file. In this XML configuration file,<br />

you are telling the <strong>Spring</strong> container that your implementation of the SearchEngine will be the MySearchEngine bean<br />

with an id of “engine”. In other words, you are assigning an identifier to your bean definition. Also, you are creating a<br />

new instance of the class Type, creating the "documentType" bean.<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!