01: Simple Spring Boot Tutorial in 8 steps

Assumes that your Java, Maven, and eclipse are set up as per: Setting up Java, Maven, and eclipse

Step 1: Create a simple maven project using the maven “archetype” plugin.

The above command creates a folder “simple-spring-boot

Screen Shot 2015-11-20 at 8.45.37 PM

Step 2: import it into eclipse by choosing File –> Import –> Maven –> Existing Maven projects and select the folder “simple-spring-boot” you had just created with Maven.

Screen Shot 2015-11-20 at 8.51.13 PM

Check “Maven Dependencies“:

Screen Shot 2015-11-20 at 9.01.58 PM

Step 3: Add Spring boot dependency “spring-boot-starter-actuator“. The actuators enable production-ready features like health, metrics, info, dump, env etc to a Spring Boot application – without having to actually implement these things yourself.

Note: The “parent” tag and the “dependency” tags having spring boot references.

What if you want to extend a different company level parent project?

You can use the Spring IO BOM (Bill Of Material) config

Note: dependency “spring-boot-dependencies” and the plugin “spring-boot-maven-plugin” with “repackage” goal.

Step 4:Run the “mvn package” command.

Check “Maven Dependencies“: “spring-boot-starter-actuator” has added

May have to click “F5” within eclipse to refersh the projects.

Spring-boot brought in all these Spring framework jars

Spring-boot brought in all these Spring framework jars

Step 5: Modify the “App.java” as shown below

Step 6: To run the jar file, you need to create a “META-INF/MANIFEST.MF” file. Using the maven jar plugin to generate the “MANIFEST.MF” file.

Note in pom.xml: “<mainClass>com.mytutorial.App</mainClass>”

Step 7: Ready to build the “jar” now.

The “target” directory will have the jar file “simple-spring-boot-1.0-SNAPSHOT.jar”

Deployable "jar" is built

Deployable “jar” is built

Step 8: Deploy the very simple Spring boot application & run as shown below

right-click on the jar, and then select “properties” to get the full file path of the jar file.

“c:/projects/simple-spring-boot/target/simple-spring-boot-1.0-SNAPSHOT.jar”

Output:

Hello Spring Boot!

Conclusion:

If you look at the packaged “simple-spring-boot-1.0-SNAPSHOT.jar” with

you will get

UBER jar with Spring spring-boot-maven-plugin

UBER jar with Spring spring-boot-maven-plugin

Java does not provide any standard way to load nested jar files, so we use “uber” jars. An uber jar simply packages all classes, from all jars, into a single archive. The following plugin creates an uber jar.

In the next tutorial I will expand this to a simple “RESTful” web service. Simple Spring Boot Restful Web Service Tutorial


Java developer & architect Q&As

Java developers Q&As

Top