What is spring boot?
There are probably a lot of explanations about what it is, but my take on it is simple:
Spring Boot solves your classpath problems without troubling you thinking about it.
For example: Let's say you want to build a standard Spring MVC application.
You create a maven project (or gradle), you add spring-web to classpath and you get it working.
You may be missing few jars so you simple add it to your pom.xml
With Spring Boot, you don't need to do so. Once you add a class and annotate it with @RestController, Spring will automatically add all the jars to the classpath that Spring thinks you need.
It may be more than you really need, but this is an opinionated view - take it or leave it.
Interesting features
Examples
Very Basic Application
The class that would be generated in your project (Application) will have those lines:
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
If you assign the return value of "run" to ApplicationContext then you can access all your beans.
Basic Application
So if you will add a code:
@RestController
public class ProductVerionController {
@RequestMapping("/version")
public String getVersion() {
return "1.0.0";
}
}
There are few interesting points about this behavior:
- You run the program as simple Java but it is run as a web server (with embedded tomcat)
- There is not "web application name" in the URL, it is as if you deployed it to the ROOT of your tomcat - that aligns well with how Pivotal CloudFoundry deploys java apps and confirms that Spring Boot may be the way for building and deploying CF apps in the future
Basic Application + Some HTML files
<resources location="/resources/" mapping="/resources/**" >
In the case of Spring Boot, you don't have a web server, but you have a simple java application.
What you need to do in this case is something very simple.
Add either a folder named "resources" or "static" into src/main/resources folder, and any static HTML that you have there will be served by your app.
Here is my project structure:
and if you run an application than the URLs
http://localhost:8080/resources.html
and
http://localhost:8080/static.html
will return the respective HTML pages that I placed in a predefined folders I created
Next time - WAR files with Spring Boot.