How to programmatically deploy a process definition by rest api

I have created a spring-boot application from https://start.camunda.com/ . and I put the following class for a rest API in same code so that it can register process. I hit rest(/test) end and it should be showing process definition in cockpit but it is not working and also giving any error too when hitting same API again and again:

package com.example.workflow.rest;

import org.camunda.bpm.engine.ProcessEngines;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ApplicationResource {


  @GetMapping("/test")
  public String restResource() {
    BpmnModelInstance modelInstance = Bpmn.createProcess()
        .name("Example process")
        .executable()
      .startEvent()
      .userTask()
        .name("Some work to do")
      .endEvent()
      .done();
    ProcessEngines.getDefaultProcessEngine().getRepositoryService().createDeployment()
    .addModelInstance("test", modelInstance).deploy();
    return "hi";
  }

}

Hi @mittalramsharan

I read about it at the following link

Hope this helps you

what I am missing here that after I run my rest end. I am not able to see process definition in Camunda’s cockpit.