Creating Simple Java Microservice
Last updated: 2025-09-14
This section shows how to create a simple REST Microservice service based on Java Jackson and Jersy API’s in no-time.
Steps:
-
Create Maven project with the following pom.xml:
Unresolved include directive in modules/6.x.x/pages/frameworks/jk-framework/jk-framework-service/java-simple-microservice-tutorial.adoc - include::inc/simple-service/pom.xml[]
If you are using Eclipse, be sure to refresh your project (select your project→ right click→ Maven→ Update Project) |
-
Create Person class as a model class at src/main/java/com/app/model/Person.java such as the following:
Unresolved include directive in modules/6.x.x/pages/frameworks/jk-framework/jk-framework-service/java-simple-microservice-tutorial.adoc - include::inc/simple-service/src/main/java/com/app/model/Person.java[]
-
Create ExampleService as sREST service at src/main/java/com/app/service/ExampleService.java, such as the following:
Unresolved include directive in modules/6.x.x/pages/frameworks/jk-framework/jk-framework-service/java-simple-microservice-tutorial.adoc - include::inc/simple-service/src/main/java/com/app/service/ExampleService.java[]
-
Create App class at src/main/java/com/app/App.java for quick testing with the following contents:
Unresolved include directive in modules/6.x.x/pages/frameworks/jk-framework/jk-framework-service/java-simple-microservice-tutorial.adoc - include::inc/simple-service/src/main/java/com/app/App.java[]
Run your App class, you should see something like this in your console:


The available end-points are:
-
POST: http://localhost:8080/app/example/hello with Person JSON object with name and age fields in the body
To call the this Microservice from Java client, you can follow this - Create Simple Microservice Client
Full example source-code can be found at https://github.com/smartapi-com/j-framework-microservice |