<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Add REST controller to desired package, for example to com.example.myproject.web.rest (reference):
package com.example.myproject.web.rest;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
public class VersionController {
@RequestMapping("/api/version")
public ResponseEntity get() {
final Map<String, String> responseParams = new HashMap();
responseParams.put("requestStatus", "OK");
responseParams.put("version", "0.1-SNAPSHOT");
return ResponseEntity.ok().body(responseParams.build());
}
}
Start Spring Boot application (reference).
Your controller is accessible at the address http://localhost:8080/api/version.