Updated: Jun 10
Spring Boot is the framework that builds on top of the Spring framework. It is used within Maven—the powerful project-management tool that is based on a POM (project object model). Maven is useful for building projects (primarily Java) and adding dependencies.
Benefits of Spring Boot and Maven
The main reason for using Maven is that you can easily add all libraries into the project with one sample XML file. Instead of downloading and then importing the jar file for each library, you can add the libraries by simply adding dependencies in the pom.xml.
The benefit of using Spring Boot is that it makes developing and deployment much easier and faster. It removes the need to write a lot of boilerplate code as well as annotations and XML configurations. Spring Boot is much easier to set up and learn than other similar frameworks.
A simple example
The most convenient way to create a Spring Boot project is first, go to https://start.spring.io/
Click on Generate, then download and unzip the file.
Open Eclipse and click on import project, then select an existing Maven project:
Find the directory, then click Finish:
As you can see, most of the structure is generated. We just need to add a static folder for the source. Spring Boot automatically maps all the files listed under the static folder:
Let’s create a helloword.html, and save it under the static folder:
Now, run this application: open a browser and type http://localhost:8080/helloword.html
If you want to change the URL for the html file, just add a control class:
Let’s restart the application by typing: http://localhost:8080/hello in the browser:
You can easily find Maven dependencies for most frameworks from Google, and add as many as you need in the pom.xml file.
That’s how simple it is to create a Spring Boot project. Let’s now see how easy it is to deploy this project with Spring Boot and Maven:
Open the terminal, cd to the location of the file, then type: mvn package
As you can see, it will generate the jar file under target:
cd to target, then type: Java -jar -0.0.1-SNAPSHOT.jar
Give it a try! Building a sample of your own will give you a better understanding of how the server works.