Spring Boot with REST – Example

You just want to see an minimal example of Spring boot with REST.

This page is for you.

This example is a part of  Spring Boot with all examples

Full Code with Spring Boot 1.5.8.RELEASE:


What you need for run this:

  • Maven 3
  • Java 8

What the code will do:

  • Call an url  then the service will return only data without html


This is the file structure:

In pom.xml you need this:

The lines that are highlighted are for Spring Boot.

Then you create a SpringBootApplication class, for example MyApplication.

@SpringBootApplication is to define that this class is a SpringBootApplication class.

Next, create an endpoint when you access http://localhost:8080/api/count


run this in console:

Then run this to start:

You should see something like this:

Open a browswer and try to go to this url:

You should see this:

You can stop the process by just Ctrl+C (in Windows)

You can create a executable jar file by run:

Then you should have this jar in your the “target” folder. For example,

You can also run this command to start the spring boot from the jar file.

Try to access to http://localhost:8080/api/count. It will give you the same result.