Spring is a very powerful framework to build enterprise grade applications. But there is a catch. You need to set it up first which could be a daunting task for some developers. If you are using maven there are countless archetypes out there to build a spring application. Or you may want to use Opentides which is a framework to quickly setup your web application using Spring Framework. Or if you are the old school type you can just memorize all the dependencies then put all of them in a dynamic web application. That’s just starting a Spring Application. You still need to configure your ORM. You still need to configure your security. You still need to configure other things that you will need for your application.
Enter Spring Boot. From the project page Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. Think of play framework. But rather downloading a whole application and using that to create a web application, Spring Boot just helps your favorite build tool boot-up your Spring Application. It favors convention over configuration so guess what. It has zero XML files required.
In this example we will be using Maven. Create a simple web application. In your pom.xml add the following:
org.springframework.boot spring-boot-starter-parent 1.2.5.RELEASE org.springframework.boot spring-boot-starter-web
Create a controller for our home page:
@RestController public class HelloSpringBootController { @RequestMapping("/") String home() { return "Hello World"; } }
Then create a new class Application.java with the following codes:
@SpringBootApplication public class Application { public static void main(String [] args) { SpringApplication.run(Application.class, args); } }
Run Application.java. Then access your newly setup web application through http://localhost:8080.
That’s it. You have successfully setup a spring web application with zero configurations. It adds an embedded Tomcat server in your application for it to run without needing an external server. Spring boot also uses a lot of defaults. In this example since we do not specify the JPA provider it will use Hibernate and will use HSQLDB as the database. For the front end, it will use Thymeleaf templating engine. To override these defaults, just add new dependencies in the pom.xml file.
To know more about this project visit http://projects.spring.io/spring-boot/.