25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 19 ■ <strong>Spring</strong> Boot, Simplifying Everything<br />

Listing 19-9 shows the MyDocumentService class that will call the repository to access all of the data from the<br />

in-memory database. For now, you are only implementing it to retrieve the document records.<br />

Listing 19-10 shows the MyDocumentsController class, which is the RESTful calls entry class. You are<br />

implementing a single method just to prove that with Groovy it is even easier to create enterprise-ready applications.<br />

Now you need to create the main class that will be the bootstrap of the application. See Listing 19-11.<br />

Listing 19-11. app.groovy<br />

@Grab("org.hsqldb:hsqldb:2.2.9")<br />

@Grab("org.codehaus.groovy:groovy-sql:2.0.1")<br />

@Configuration<br />

class MyDocuments {<br />

//Extra configuration<br />

}<br />

beans {<br />

importBeans("jdbc.xml")<br />

}<br />

Listing 19-11 shows the MyDocuments class, which is the bootstrap for the <strong>Spring</strong> Boot application. The new<br />

<strong>Spring</strong> 4 provides support for a <strong>Spring</strong> DSL context, so in this script you are including it just to prove that you can<br />

actually use external configurations. The book’s companion source code contains all the scripts used in this section.<br />

Now how do you run it? You need to have <strong>Spring</strong> Boot installed. (For more information about how to install<br />

<strong>Spring</strong> Boot, see Appendix A.) From the command line, just execute the following command:<br />

spring run *.groovy<br />

This command will execute <strong>Spring</strong> Boot and it will automatically recognize what to do. Figure 19-3 shows the<br />

output of this command.<br />

275

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

Saved successfully!

Ooh no, something went wrong!