spring-boot – Spring Boot- Hibernate-REST Integration – Add REST support

  1. Add spring-boot-starter-web dependency to pom.xml. You may skip version tag, if you are using spring-boot-starter-parent as the parent of your pom.xml (reference).
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  1. 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());
        }
    }    
    
  2. Start Spring Boot application (reference).

  3. Your controller is accessible at the address http://localhost:8080/api/version.

if you want to reproduce, please indicate the source:
spring-boot – Spring Boot- Hibernate-REST Integration – Add REST support - CodeDay