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 19 ■ <strong>Spring</strong> Boot, Simplifying Everything<br />

@Configuration<br />

@EnableAutoConfiguration<br />

@ComponentScan("com.apress.isf.spring")<br />

public class MyDocumentsApp {<br />

}<br />

@Bean<br />

public DataSource dataSource() {<br />

EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();<br />

EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).<br />

addScript("META-INF/data/schema.sql").<br />

addScript("META-INF/data/data.sql").build();<br />

return db;<br />

}<br />

public static void main(String[] args) {<br />

<strong>Spring</strong>Application.run(MyDocumentsApp.class,args);<br />

}<br />

Listing 19-4 shows the <strong>Spring</strong> Boot application. The main method executes the <strong>Spring</strong>Application.run method<br />

and <strong>Spring</strong> Boot will take care of the rest. Now, open a terminal and run the following command:<br />

gradle :ch19:bootRun<br />

You should get the output shown in Figure 19-1. When you run the above command for the first time, the<br />

spring-boot plug-in will download all the necessary libraries needed to run the application. Because you are<br />

scanning all the components, services, and repositories that belong to the com.apress.isf.spring package, it will<br />

automatically create a web context, so it will open port 8080 for incoming HTTP requests and you will be able to do<br />

all the RESTful calls.<br />

267

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

Saved successfully!

Ooh no, something went wrong!