Spring Boot is something really exciting (see 1.3.0 release note to convince yourself), every Java geek should have hear about it !
Let's play with it, with easy understandable examples :)
For spelling, sorry, I'm French...
First, we need an IDE (ok it's not a requirement but we don't want to have an headache...) and setup few little things: here is the wiki.
MVP MVP !
These 2 projects have the minimum to expose a REST service with Jersey and Spring.
Difference between them ? Spring Boot of course !
hello-world-sb-jersey-minimum
is simply the Spring Boot version of hello-world-jersey-minimum
.
For both, I followed Servlet 3.0 spec, thanks to this Xebia tuto.
This project demonstrate how it is easy to setup logs with Spring Boot.
- I add a embedded
application.properties
to be able to default some Spring Boot settings, here onlyspring.application.name
. - Have a look at logback-spring.xml
- By default Spring Boot use a log rotation based on file size, I prefer time based rotation so I override the
FILE
appender and keep other default settings. - Note that I use
<springProperty name="spring.application.name" source="spring.application.name"/>
to refer to the property I have set in the embeddedapplication.properties
and use it as the base name of log files.
- By default Spring Boot use a log rotation based on file size, I prefer time based rotation so I override the
See how Spring Boot detect changes on the classpath and restart automatically app to reflect changes (more infos here: https://spring.io/blog/2015/06/17/devtools-in-spring-boot-1-3).
- Note that it doesn't work when app is running with maven command line, you have to use
Run As > Java Application
orRun As > Spring Boot App
You want to make some integration tests, see how it is easy to start your app and call it from your JUnit test
Example of an app that check args at boot and exit if it isn't compliant.
- Focus on ArgsValidator class to see how it works (as always, it is easy understandable).
- Also notice
<configuration><executable>true</executable></configuration>
inpom.xml
, this simple param convert the output jar file to a fully executable one: - Without this instruction, you have to start your jar with
java -jar myapp.jar
- With this instruction, you have to start your jar like any executable:
./myapp.jar
The last but not the least : the Actuator.
With juste few lines of conf, it enable a lof of production features to control and check your app.