app.groovy
class Demo {
public static String foo() {
return "Hello Spring Boot";
}
}
class Employee {
String name;
int salary;
public Employee() {
this.name = "";
this.salary = 0;
}
public Employee(String n, int s) {
this.name = n;
this.salary = s;
}
}
@RestController
class HelloWorld {
@RequestMapping("/")
String hello() {
"Hello JournalDev World." + Demo.foo();
}
@RequestMapping("/emps")
public List<Employee> getEmps() {
List<Employee> list = new ArrayList<>();
list.add(new Employee("Alfi", 20000))
list.add(new Employee("Nikhil", 30000))
return list;
}
@RequestMapping("/sqr")
String getSqr(@RequestParam("num") int x) {
"Square of " + x + " is " + (x * x);
}
@RequestMapping("/emp")
public ResponseEntity<Employee> readRawJson(@RequestBody Employee e) {
System.out.println("\n=============="+ e.name +"==============\n");
return ResponseEntity.ok(e);
}
}
To run via CLI
spring run app.groovy — –server.port=9000

Ref Link:
https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html