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 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />

If you run Listing 9-7 with<br />

gradle :ch09:test<br />

then the test will pass, because you have added the initialize method and you can count on the data being there.<br />

Embedding a Database<br />

In the XML configuration (see Listing 9-11) you can see the DocumentRepository class and the initialize method;<br />

there should be a better way to initialize your database, right? Well, the <strong>Spring</strong> <strong>Framework</strong> offers different ways to use the<br />

JDBC; for test purposes it provides a way to use the HSQLDB in an embedded way through an xmlns:jdbc namespace.<br />

Let’s modify the XML configuration to use these new features from the xmlns:jdbc namespace (see Listing 9-12).<br />

Listing 9-12. mydocuments-jdbc-embedded-context.xml<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!