Getting Started With WSO2 Microservices Framework for Java

Engineer, Tech Lead and Technopreneur

WSO2 Microservices Framework for Java (MSF4J) is lightweight, fast runtime and annotation-based programming model offers the best option to create microservices in Java.

To getting started with MSF4J is very easy. You need to have following software installed in  your machine to get started.

  • JDK 1.8
  • Maven 3

Open a terminal and run below command to create the project structure of your first MSF4J project

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

Once project is created, open org.example.service.HelloService class and replace its contents with following

package org.example.service; 


public class HelloService{

 public String hello(@PathParam("name") String name, @QueryParam("username") String username) {
    return "Hello " + username + " : from " + name;


Open org.example.service.Application class and replace its contents with following

package org.example.service;

import org.wso2.msf4j.MicroservicesRunner;

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

Now go to the terminal and build the package

mvn package

Run your micro service project

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

That’s it. Open http://localhost:8080/hello/wso2?username=Dilan to test your micro service that you’ve written in Java

Awesome! You will see this response form your first micro service. Change the value of wso2 (path parameter) and Dilan (query parameter) of the above URL to get different outputs

To read more about MSF4J, visit

2,417 total views, 4 views today


Feel Free to ask questions and share your thoughts