To implement a rest controller you need the following dependency in your pom.xml:
<dependencys>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
</dependencys>
A sample implementation for a simple RestController is shown below.
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ExampleController {
@GetMapping(path = "/demo/ping")
ResponseEntity<String> ping() {
return ResponseEntity.ok("pong");
}
}
The endpoint can be addressed with the following curl command:
curl localhost:8080/demo/ping