Spring Boot CLI

The Spring Boot CLI (Command Line Interface) is a command line tool that you can use to quickly prototype with Spring. It lets you run Groovy scripts, which means that you have a familiar Java-like syntax without so much boilerplate code.

You do not need to use the CLI to work with Spring Boot, but it is definitely the quickest way to get a Spring application off the ground.

Installation

Download

wget https://www.dropbox.com/s/k3qns68vsk3vzv3/spring-boot-cli-2.0.3.RELEASE-bin.zip
unzip spring-boot-cli-2.0.3.RELEASE-bin.zip

cd spring-2.0.3.RELEASE/

Environment Variables

echo 'export PATH="~/spring-2.0.3.RELEASE/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Shell Completion

sudo ln -s ./shell-completion/bash/spring /etc/bash_completion.d/spring

Verify

spring --version
Spring CLI v2.0.3.RELEASE

Quick-start Spring CLI Example

cat << EOF > app.groovy
@RestController
class ThisWillActuallyRun {
    @RequestMapping("/hello")
    String home() {
        "Hello World from Admatic!\n"
    }
}
EOF
spring run app.groovy
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-07-25 05:54:37.771  INFO 11389 --- [       runner-0] o.s.boot.SpringApplication               : Starting application on instance-2 with PID 11389 (started by hadoop in /home/hadoop/spring-2.0.3.RELEASE)
2018-07-25 05:54:37.782  INFO 11389 --- [       runner-0] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-07-25 05:54:38.077  INFO 11389 --- [       runner-0] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3af55bf1: startup date [Wed Jul 25 05:54:38 UTC 2018]; root of context hierarchy
2018-07-25 05:54:39.731  INFO 11389 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-07-25 05:54:39.770  INFO 11389 --- [       runner-0] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-25 05:54:39.770  INFO 11389 --- [       runner-0] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-25 05:54:39.786  INFO 11389 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2018-07-25 05:54:39.844  INFO 11389 --- [ost-startStop-1] org.apache.catalina.loader.WebappLoader  : Unknown loader org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@5b705c5b class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
2018-07-25 05:54:39.899  INFO 11389 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-25 05:54:39.899  INFO 11389 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1826 ms
2018-07-25 05:54:40.074  INFO 11389 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-07-25 05:54:40.083  INFO 11389 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-25 05:54:40.084  INFO 11389 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-25 05:54:40.084  INFO 11389 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-25 05:54:40.084  INFO 11389 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-25 05:54:40.285  INFO 11389 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-25 05:54:40.649  INFO 11389 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3af55bf1: startup date [Wed Jul 25 05:54:38 UTC 2018]; root of context hierarchy
2018-07-25 05:54:40.749  INFO 11389 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String ThisWillActuallyRun.home()
2018-07-25 05:54:40.756  INFO 11389 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-07-25 05:54:40.757  INFO 11389 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-07-25 05:54:40.799  INFO 11389 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-25 05:54:40.800  INFO 11389 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-25 05:54:41.259  INFO 11389 --- [       runner-0] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-07-25 05:54:41.309  INFO 11389 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-07-25 05:54:41.314  INFO 11389 --- [       runner-0] o.s.boot.SpringApplication               : Started application in 4.256 seconds (JVM running for 5.873)

Open localhost:8080 in your favorite web browser. You should see the following output:

curl localhost:8080/hello
Hello World from Admatic!

results matching ""

    No results matching ""