Micro Services Framework for Java

WSO2 Microservices Framework for Java (MSF4J) is a lightweight high performance framework for developing and running microservices.

Learn more about MSF4J from the github page.

Performance evaluations at github page.

Hello world with MSF4J

It is really easy to define and deploy a Java microservice using WSO2 MSF4J. You simply need to annotate your service and deploy it using a single line of code.

Let’s get started by writing a hello world MSF4J microservice.

You can use the msf4j-microservice Maven archetype to create your first MSF4J project. Make sure you have JDK 1.8 and Maven 3.x installed, and run the following command.

mvn archetype:generate -DarchetypeGroupId=org.wso2.msf4j \
-DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=2.1.0 \
-DgroupId=org.example -DartifactId=Hello-Service -Dversion=0.1-SNAPSHOT \
-Dpackage=org.example.service -DserviceClass=

This will generate a project structure for you to quickly get started. Next navigate to the Hello-Service directory. You will find a pom.xml file and also an src directory.


This pom file inherits from the msf4j-service/pom.xml. It provides a way of setting things up quickly with minimum amount of configuration. Click here for more information.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


    <name>WSO2 MSF4J Microservice</name>



You don’t need to change anything in this pom.xml file.


Change the org.example.service.HelloService class as follows to echo back the name input parameter. You can remove the auto generated code and replace it with the following code segment:

package org.example.service; 

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

public class HelloService {

    public String hello(@PathParam("name") String name) {
        return "Hello " + name;



This is the one-liner to deploy your service using WSO2 MSF4J.

public class Application {
    public static void main(String[] args) {
        new MicroservicesRunner()
                .deploy(new HelloService())

Build the Service

Run the following Maven command. This will create the fat jar Hello-Service-0.1-SNAPSHOT.jar in the target directory.

mvn package

This fat jar is a jar file that contains your microservice as well as all its dependencies.

Run the Service

You just have to run the following command to get your service up and running.

java -jar target/Hello-Service-*.jar

Test the Service with cURL

Run the following command or simply go to [http://localhost:8080/hello/wso2] (http://localhost:8080/hello/wso2) from your browser.

curl http://localhost:8080/hello/wso2

You should see a response that prints “Hello wso2”