Using Spring Boot Cli

03 March 2019, tags: spring-boot groovy

The easiest way to get started with Spring is to setup SpringBoot with their CLI tool. You can bootstrap a web application with a single Groovy script!

Now unzip and setup PATH to use the spring command.

unzip spring-boot-cli-2.0.5.RELEASE-bin.zip
export PATH=`pwd`/spring-2.0.5.RELEASE/bin:$PATH

Create a simple groovy app script

// file: app.groovy
@RestController
class HelloApp {
    @RequestMapping("/")
    String home() {
        return "Hello World!"
    }
}

Now run it and test it with a browser:

spring run app.groovy
open http://localhost:8080

Or you can create a full SpringBoot project with Maven build:

# Or create a new project
spring init -d=web -x --package-name zemian.springbootstarter.hello hello-spring-boot
cd hello-spring-boot
./mvnw spring-boot:run
open http://localhost:8080

You can learn more from my starter project: https://github.com/zemian/spring-boot-starter


Older posts are available in the archive.