Microservices Framework for Java (MSF4J) - HelloWorld!

In a recent article: Microservices in a minute, I introduced a lightweight microservice framework: WSO2 MSF4J. That tutorial shows you how to create a microservice in minutes using the Maven archetype. However, the libraries available in the public Maven repositories are bit older and there are new releases after MSF4J 2.0.1 which are available in WSO2's Maven repository. This article shows you how to create a microservice using the latest stable release of MS4J Framework.

  • Java Development Kit 1.8
  • Apache Maven 3.x
  • Postman or CURL
  • Eclipse IDE for Java EE Developers / Any IDEs with Maven support
Step 1:
Create a new Maven project in Eclipse using the following properties:
Group Id:   com.javahelps
Artifcat Id: msf4j-helloworld

Step 2:
Modify the pom.xml as shown below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <!-- Define Java version and the MSF4J version -->

    <!-- Use the WSO2's repository -->
            <name>WSO2 Internal Repository</name>

    <!-- Add the dependency -->

    <!-- Optionally deine the main class -->
Note that the properties tag defines the Java version which must be 1.8 or greater and the MSF4J version which is 2.2.2 (the latest stable release at the time of writing). The repository containing the latest MSF4J builds is included using the repositories tag and the msf4j-core is added as the dependency. Finally the build plugin is used to define the main class which is optionaly if you do not want to create the JAR file.

If you are using Eclipse, save all the changes and right click on the project, goto Maven → Update Project... and click OK on the apperaed dialog to import the changes we have done in the pom file.
Step 3:
Create a new package 'com.javahelps.service' in src/main/java directory.

Step 4:
Create a new service class named HelloService.java with the following code.
package com.javahelps.service;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;

public class HelloService {

    public String get() {
        System.out.println("GET invoked");
        return "Hello from WSO2 MSF4J";

    public void post() {
        System.out.println("POST invoked");

    public void put() {
        System.out.println("PUT invoked");

    public void delete() {
        System.out.println("DELETE invoked");
This code defines the base URL '/service' at the begining of the class definition using @Path annotation and the Java methods to handle the HTTP methods: GET, POST, PUT and DELETE are defined.

Step 5:
Create another class Application.java inside the same package. Remember this is the main class defined in the pom file.
package com.javahelps.service;

import org.wso2.msf4j.MicroservicesRunner;

public class Application {

    public static void main(String[] args) {
        new MicroservicesRunner()
        .deploy(new HelloService())
This class creates an instance of the HelloSevice class and deply it as a service at the default port: 8080. If you want to change the default port, you can pass it as a parameter to the MicroservicesRunner constructor.

Microservices Framework for Java (MSF4J) - HelloWorld

Step 6:
Now, this is the time to run our microservice. You can simply right-click on the Application.java and run it as a Java application but I prefer to use Apache Maven, so the Maven command to build the JAR file and execute the microservice is given below:
mvn clean package exec:java

Step 7:
To test the service, send a request from POSTMAN or any other tools. This time I use curl to send a GET request to the service.
curl http://localhost:8080/service

Microservices Framework for Java (MSF4J) - HelloWorld

I hope you have enjoyed the simplicity of MSF4J. Feel free to comment below if you have any questions or doubts.

Find the project @ GitHub.
Next Post »


Write comments
September 9, 2020 at 1:44 AM delete

The caliber of information that you're offering is merely wonderful.
user interface design companies


Contact Form


Email *

Message *