Introducing Spring Framework
Introducing Spring Framework Introducing Spring Framework
Chapter 3 ■ Applying Different Configurations } public Document getDoc3() { return doc3; } public void setDoc3(Document doc3) { this.doc3 = doc3; } public Document getDoc4() { return doc4; } public void setDoc4(Document doc4) { this.doc4 = doc4; } public Document[] getAll() { return new Document[] { doc1, doc2, doc3, doc4 }; } Well, now this looks a little better. You are separating the way you are extracting the data, but how are you doing this? Well, if you recall, you were using some kind of storage method to retrieve the information, right? (See Listing 3-2.) Then you decided to reimplement your SearchEngine interface by adding a new way to get the data, and the solution was to create an interface that will be injected independent of its implementation, making your class more robust and easy to maintain. But let’s see how you are going to modify the XML so the Spring container knows about all of these new modifications. Listing 3-6 is an example of your new modified mydocuments-context.xml configuration file. This configuration holds all the information about your new DocumentDAO class implementation (DocumentRepository) and how it’s being injected in your SearchEngine implementation. Listing 3-6. mydocuments-context.xml 30
Chapter 3 ■ Applying Different Configurations Analyzing Listing 3-6, you can see that you are using some references like the ref attribute to assign a value; there’s a new declaration of the ServiceSearchEngine; you are setting a property, documentDAO; and you are referencing the value to another bean with id "documentDAO". 31
- Page 1 and 2: THE EXPERT’S VOICE ® IN SPRING
- Page 3 and 4: Contents at a Glance About the Auth
- Page 5 and 6: Introduction This book is an introd
- Page 7 and 8: Part I Spring Framework Basics The
- Page 9 and 10: Chapter 1 ■ Your First Spring App
- Page 11 and 12: Chapter 1 ■ Your First Spring App
- Page 13 and 14: Chapter 1 ■ Your First Spring App
- Page 15 and 16: Chapter 1 ■ Your First Spring App
- Page 17 and 18: Chapter 1 ■ Your First Spring App
- Page 19 and 20: Chapter 2 ■ Working with Classes
- Page 21 and 22: Chapter 2 ■ Working with Classes
- Page 23 and 24: Chapter 2 ■ Working with Classes
- Page 25 and 26: Chapter 2 ■ Working with Classes
- Page 27 and 28: Chapter 2 ■ Working with Classes
- Page 29 and 30: Chapter 3 Applying Different Config
- Page 31 and 32: Chapter 3 ■ Applying Different Co
- Page 33: Chapter 3 ■ Applying Different Co
- Page 37 and 38: Chapter 3 ■ Applying Different Co
- Page 39 and 40: Chapter 3 ■ Applying Different Co
- Page 41 and 42: Spring Stereotypes Chapter 3 ■ Ap
- Page 43 and 44: Chapter 3 ■ Applying Different Co
- Page 45 and 46: Chapter 3 ■ Applying Different Co
- Page 47 and 48: Chapter 3 ■ Applying Different Co
- Page 49 and 50: Chapter 4 ■ Using Beans Scopes pu
- Page 51 and 52: Chapter 4 ■ Using Beans Scopes Th
- Page 53 and 54: Chapter 4 ■ Using Beans Scopes @A
- Page 55 and 56: Chapter 4 ■ Using Beans Scopes do
- Page 57 and 58: Chapter 5 ■ Working with Collecti
- Page 59 and 60: Chapter 5 ■ Working with Collecti
- Page 61 and 62: Chapter 5 ■ Working with Collecti
- Page 63 and 64: Chapter 5 ■ Working with Collecti
- Page 65 and 66: Chapter 6 ■ Using Resource Files
- Page 67 and 68: Chapter 6 ■ Using Resource Files
- Page 69 and 70: Chapter 6 ■ Using Resource Files
- Page 71 and 72: Chapter 6 ■ Using Resource Files
- Page 73 and 74: Chapter 6 ■ Using Resource Files
- Page 75 and 76: Chapter 6 ■ Using Resource Files
- Page 77 and 78: Chapter 7 Testing Your Spring Appli
- Page 79 and 80: Chapter 7 ■ Testing Your Spring A
- Page 81 and 82: Chapter 7 ■ Testing Your Spring A
- Page 83 and 84: Chapter 7 ■ Testing Your Spring A
Chapter 3 ■ Applying Different Configurations<br />
}<br />
public Document getDoc3() {<br />
return doc3;<br />
}<br />
public void setDoc3(Document doc3) {<br />
this.doc3 = doc3;<br />
}<br />
public Document getDoc4() {<br />
return doc4;<br />
}<br />
public void setDoc4(Document doc4) {<br />
this.doc4 = doc4;<br />
}<br />
public Document[] getAll() {<br />
return new Document[] { doc1, doc2, doc3, doc4 };<br />
}<br />
Well, now this looks a little better. You are separating the way you are extracting the data, but how are you<br />
doing this? Well, if you recall, you were using some kind of storage method to retrieve the information, right?<br />
(See Listing 3-2.) Then you decided to reimplement your SearchEngine interface by adding a new way to get the data,<br />
and the solution was to create an interface that will be injected independent of its implementation, making your class<br />
more robust and easy to maintain. But let’s see how you are going to modify the XML so the <strong>Spring</strong> container knows<br />
about all of these new modifications. Listing 3-6 is an example of your new modified mydocuments-context.xml<br />
configuration file. This configuration holds all the information about your new DocumentDAO class implementation<br />
(DocumentRepository) and how it’s being injected in your SearchEngine implementation.<br />
Listing 3-6. mydocuments-context.xml<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
30