Spring Boot CLI
i
Spring Boot CLI
About the Tutorial
Spring Boot CLI is a command line tool, which is used for a quick start with Spring. It
allows running Groovy scripts. Groovy scripts are similar to Java code without any
boilerplate code. Spring CLI helps to bootstrap a new project or write custom command
for it.
Audience
This tutorial will be useful for most Java developers, starting from beginners to experts.
After completing this tutorial, you will find yourself at a moderate level of expertise in
Spring Boot CLI, from where you can take yourself to next levels.
Prerequisites
Knowledge of basic Java programming language and Spring is the only prerequisite for
learning the concepts explained in this tutorial.
Copyright & Disclaimer
Copyright 2018 by Tutorials Point (I) Pvt. Ltd.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@[Link]
i
Spring Boot CLI
Table of Contents
About the Tutorial ............................................................................................................................................ i
Audience ........................................................................................................................................................... i
Prerequisites ..................................................................................................................................................... i
Copyright & Disclaimer ..................................................................................................................................... i
Table of Contents ............................................................................................................................................ ii
1. Spring Boot CLI — Overview ..................................................................................................................... 1
Features ........................................................................................................................................................... 1
2. Spring Boot CLI — Environment Setup ...................................................................................................... 2
Step 1 - Setup Java Development Kit (JDK) ...................................................................................................... 2
Step 2 - Install Spring Boot CLI ......................................................................................................................... 2
Step 3 - Verify installation ............................................................................................................................... 3
3. Spring Boot CLI — Hello World Example ................................................................................................... 4
Step 1: Create source Folder ........................................................................................................................... 4
Step 2: Create Source File ................................................................................................................................ 4
Step 3: Run the application ............................................................................................................................. 4
Step 4: Browse the application in Browser...................................................................................................... 7
4. Spring Boot CLI — "grab" Dependency Deduction..................................................................................... 8
Grab Hints ........................................................................................................................................................ 8
5. Spring Boot CLI — "grab" Co-ordinates Deduction .................................................................................. 10
6. Spring Boot CLI — Default Statements .................................................................................................... 55
Default Imports ............................................................................................................................................. 55
Automatic Main Method ............................................................................................................................... 56
7. Spring Boot CLI — Starter Thymeleaf Project .......................................................................................... 57
Run the application ....................................................................................................................................... 58
Browse the application in Browser ................................................................................................................ 59
Important points ........................................................................................................................................... 59
ii
Spring Boot CLI
8. Spring Boot CLI — Testing Application .................................................................................................... 60
Run the application ....................................................................................................................................... 60
Important points ........................................................................................................................................... 61
9. Spring Boot CLI — Packaging Application ................................................................................................ 62
Package the application ................................................................................................................................. 62
Include/Exclude ............................................................................................................................................. 62
Running the Executable Jar ........................................................................................................................... 63
Browse the application in Browser ................................................................................................................ 63
10. Spring Boot CLI — Creating Project ......................................................................................................... 64
Create Gradle project .................................................................................................................................... 64
11. Spring Boot CLI — Using Shell ................................................................................................................. 65
Running Commands in Shell .......................................................................................................................... 65
Testing the application in shell ...................................................................................................................... 65
iii
1. Spring Boot CLI — Overview Spring Boot CLI
The Spring Boot CLI is a Command Line Interface for Spring Boot. It can be used for a
quick start with Spring. It can run Groovy scripts which means that a developer need not
write boilerplate code; all that is needed is focus on business logic. Spring Boot CLI is the
fastest way to create a Spring-based application.
Features
In this section, we will look at the different features of Spring Boot CLI −
It provides an interface to run and test Spring Boot Application from the Command
Prompt.
It internally uses Spring Boot Starter and Spring Boot AutoConfigurate components
in order to resolve all dependencies and execute the application.
It contains Groovy compiler and Grape Dependency Manager.
It supports Groovy Scripts without external Groovy installation.
It adds Spring Boot defaults and resolve all dependencies automatically.
1
2. Spring Boot CLI — Environment Setup Spring Boot CLI
Spring is a Java-based framework; hence, we need to set up JDK first. Following are the
steps needed to setup Spring Boot CLI along with JDK installation.
Step 1 - Setup Java Development Kit (JDK)
You can download the latest version of SDK from Oracle's Java site − Java SE
Downloads. You will find instructions for installing JDK in downloaded files. Follow the
given instructions to install and configure the setup. Finally set PATH and JAVA_HOME
environment variables to refer to the directory that contains Java and Javac, typically
java_install_dir/bin and java_install_dir respectively.
If you are running Windows and have installed the JDK in C:\jdk1.6.0_15, you would
have to put the following line in your C:\[Link] file −
set PATH=C:\jdk1.6.0_15\bin;%PATH%
set JAVA_HOME=C:\jdk1.6.0_15
Alternatively, on Windows NT/2000/XP, you will have to right-click on My Computer,
select Properties → Advanced → Environment Variables. Then, you will have to update the
PATH value and click the OK button.
On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.6.0_15 and you
use the C shell, you will have to put the following into your .cshrc file −
setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.6.0_15
Step 2 - Install Spring Boot CLI
You can download the latest version of Spring Boot CLI API as ZIP archive
from [Link] Once you
download the installation, unpack the zip distribution into a convenient location. For
example, in E:\Test\[Link] on Windows, or /usr/local/spring-
[Link] on Linux/Unix.
Make sure you set your CLASSPATH variable on this directory properly otherwise, you will
face a problem while running your application.
Or set the path in Command Prompt temporarily to run the Spring Boot application as
shown below −
E:/Test/> set path=E:\Test\[Link]\bin;%PATH%
2
Spring Boot CLI
Step 3 - Verify installation
Run the following command on the Command Prompt to verify the installation –
E:/Test/> spring --version
It should print the following output confirming the successful installation −
Spring CLI [Link]
3
3. Spring Boot CLI — Hello World Example Spring Boot CLI
In this example, we will create a Spring Boot + MVC + Rest-based Web application.
Step 1: Create source Folder
Create a folder FirstApplication in E:\Test folder.
Step 2: Create Source File
Create [Link] file in E:\Test folder with the following source code –
@RestController
class FirstApplication {
@RequestMapping("/")
String welcome() {
"Welcome to [Link]"
}
}
Step 3: Run the application
Type the following command –
E:/Test/> spring run [Link]
Now Spring Boot CLI will come into action, download the required dependencies, run the
embedded tomcat, deploy the application and start it. You can see the following output on
console –
Resolving
dependencies..........................................................
...............................................................................
.
........................
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
4
Spring Boot CLI
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: ([Link])
2017-11-07 [Link].703 INFO 5528 --- [ runner-0]
[Link]:
Starting application on ...
2017-11-07 [Link].707 INFO 5528 --- [ runner-0]
[Link]:
No active profile set, falling back to default profiles: default
2017-11-07 [Link].067 INFO 5528 --- [ runner-0]
ationConfigEmbeddedWebApplicationContext : Refreshing
[Link]
nContext@4c108392: startup date [Tue Nov 07 [Link]
56 IST 2017]; root of context hierarchy
2017-11-07 [Link].327 INFO 5528 --- [ runner-0]
[Link] : Tomcat initialized with port(s):
8080 (http)
2017-11-07 [Link].346 INFO 5528 --- [ runner-0]
[Link] : Starting service [Tomcat]
2017-11-07 [Link].354 INFO 5528 --- [ runner-0]
[Link] : Starting Servlet Engine: Apache
Tomcat/8.5.23
2017-11-07 [Link].537 INFO 5528 --- [ost-startStop-1]
[Link] : Unknown loader
[Link]$DefaultScopePar
entClassLoader@41bfad4f class [Link]
[Link]$DefaultScopeParentClassLoader
2017-11-07 [Link].567 INFO 5528 --- [ost-startStop-1]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded
WebApplicationContext
2017-11-07 [Link].567 INFO 5528 --- [ost-startStop-1]
[Link] : Root WebApplicationContext:
initialization completed in 1500 ms
2017-11-07 [Link].725 INFO 5528 --- [ost-startStop-1]
[Link] : Mapping servlet: 'dispatcherServlet'
to [/]
2017-11-07 [Link].730 INFO 5528 --- [ost-startStop-1]
[Link] : Mapping filter:
'characterEncodingFilter' to: [/*]
2017-11-07 [Link].730 INFO 5528 --- [ost-startStop-1]
[Link] : Mapping filter:
'hiddenHttpMethodFilter' to: [/*]
5
Spring Boot CLI
2017-11-07 [Link].730 INFO 5528 --- [ost-startStop-1]
[Link] : Mapping filter:
'httpPutFormContentFilter' to: [/*]
2017-11-07 [Link].730 INFO 5528 --- [ost-startStop-1]
[Link] : Mapping filter:
'requestContextFilter' to: [/*]
2017-11-07 [Link].012 INFO 5528 --- [ runner-0]
[Link] : Looking for @ControllerAdvice:
[Link]
nContext@4c108392: startup date [Tue Nov 07 [Link] IST 2017]; root of context
hierarchy
2017-11-07 [Link].066 INFO 5528 --- [ runner-0]
[Link] : Mapped "{[/]}" onto public
[Link] [Link]()
2017-11-07 [Link].070 INFO 5528 --- [ runner-0]
[Link] : Mapped "{[/error]}" onto public
[Link]<[Link]>
[Link]([Link]
[Link])
2017-11-07 [Link].071 INFO 5528 --- [ runner-0]
[Link] : Mapped
"{[/error],produces=[text/html]}" onto public
[Link]
[Link]
.[Link]([Link],[Link]
[Link])
2017-11-07 [Link].096 INFO 5528 --- [ runner-0]
[Link] : Mapped URL path [/webjars/**] onto
handler of type [class
[Link]]
2017-11-07 [Link].096 INFO 5528 --- [ runner-0]
[Link] : Mapped URL path [/**] onto handler
of type [class
[Link]]
2017-11-07 [Link].129 INFO 5528 --- [ runner-0]
[Link] : Mapped URL path [/**/[Link]]
onto handler of type [class
[Link]]
2017-11-07 [Link].626 INFO 5528 --- [ runner-0]
[Link] : Registering beans for JMX exposure
on startup
2017-11-07 [Link].696 INFO 5528 --- [ runner-0]
[Link] : Tomcat started on port(s): 8080
(http)
2017-11-07 [Link].699 INFO 5528 --- [ runner-0]
[Link] : Started application in 3.529 seconds
(JVM running for 190.196)
6
Spring Boot CLI
2017-11-07 [Link].217 INFO 5528 --- [nio-8080-exec-1]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet
'dispatcherServlet'
2017-11-07 [Link].218 INFO 5528 --- [nio-8080-exec-1]
[Link] : FrameworkServlet
'dispatcherServlet': initialization started
2017-11-07 [Link].238 INFO 5528 --- [nio-8080-exec-1]
[Link] : FrameworkServlet
'dispatcherServlet': initialization completed in 20 ms</[Link]
Step 4: Browse the application in Browser
Our Spring-based rest application is now ready. Open URL "[Link]
and you will see the following output –
Hello World
Important points
Consider the following points to understand how Spring CLI works.
All dependency JARs are downloaded for the first time only.
Spring CLI automatically detects the dependency JARs to be downloaded based on
the classes and annotations used in code.
Finally after the compilation of the code, deploy the war file on an embedded tomcat
and start embedded tomcat server on the default port 8080.
7
4. Spring Boot CLI — "grab" Dependency Spring Boot CLI
Deduction
Standard Groovy codebase contains a @Grab annotation so that dependencies on third-
party libraries can be declared. Using the @Grab annotation, the Grape Dependency
Manager downloads jar in similar fashion as that of Maven/Gradle without any build tool.
Spring Boot attempts to deduce the required libraries based on code. For example, use of
@RestController tells that "Tomcat" and "Spring MVC" libraries are to be grabbed.
Grab Hints
The following table lists down the hints that Spring Boot uses to download third party
libraries –
[Link]. Hint & Dependency to Ddwnload/Link
1 JdbcTemplate, NamedParameterJdbcTemplate, DataSource
JDBC Application
2 @EnableJms
JMS Application
3 @EnableCaching
Caching abstraction
4 @Test
JUnit
5 @EnableRabbit
RabbitMQ
6 @EnableReactor
Project Reactor
7 extends Specification
Spock test
8 @EnableBatchProcessing
8
Spring Boot CLI
Spring Batch
9 @MessageEndpoint, @EnableIntegrationPatterns
Spring Integration
10 @EnableDeviceResolver
Spring Mobile
11 @Controller, @RestController, @EnableWebMvc
Spring MVC + Embedded Tomcat
12 @EnableWebSecurity
Spring Security
13 @EnableTransactionManagement
Spring Transaction Management
9
5. Spring Boot CLI — "grab" Co-ordinates Spring Boot CLI
Deduction
We can specify a dependency using the @Grab annotation even without specifying group
or version. For example,
@Grab('antlr')
Now Spring Boot CLI will download 2.7.7 version of antlr as it is present in Spring Boot's
default dependency metadata for 1.5.8 version. Spring Boot maintains all dependency
versions by default, which are provided in its CLI, Maven dependency management and
Gradle plugin. Whenever we declare a dependency of any of those artifacts present in
default dependency metadata without declaring a version, the version listed in its table
will be used.
The following table shows all the dependencies and their versions included in the default
metadata for Spring Boot CLI 1.5.8 version.
Group Id Artifact Id Version
antlr antlr 2.7.7
[Link] logback-access 1.1.11
[Link] logback-classic 1.1.11
[Link] logback-core 1.1.11
[Link] transactions-jdbc 3.9.3
[Link] transactions-jms 3.9.3
[Link] transactions-jta 3.9.3
[Link] couchbase-spring-cache 2.1.0
10
Spring Boot CLI
[Link] java-client 2.3.7
[Link] cassandra-driver-core 3.1.4
[Link] cassandra-driver- 3.1.4
mapping
[Link] classmate 1.3.4
[Link] jackson-annotations 2.8.0
[Link] jackson-core 2.8.10
[Link] jackson-databind 2.8.10
[Link] jackson-dataformat- 2.8.10
at avro
[Link] jackson-dataformat- 2.8.10
at cbor
[Link] jackson-dataformat-csv 2.8.10
at
[Link] jackson-dataformat-ion 2.8.10
at
[Link] jackson-dataformat- 2.8.10
at properties
[Link] jackson-dataformat- 2.8.10
at protobuf
11
Spring Boot CLI
[Link] jackson-dataformat- 2.8.10
at smile
[Link] jackson-dataformat-xml 2.8.10
at
[Link] jackson-dataformat- 2.8.10
at yaml
[Link] jackson-datatype-guava 2.8.10
[Link] jackson-datatype- 2.8.10
hibernate3
[Link] jackson-datatype- 2.8.10
hibernate4
[Link] jackson-datatype- 2.8.10
hibernate5
[Link] jackson-datatype-hppc 2.8.10
[Link] jackson-datatype-jaxrs 2.8.10
[Link] jackson-datatype-jdk8 2.8.10
[Link] jackson-datatype-joda 2.8.10
[Link] jackson-datatype-json- 2.8.10
org
12
Spring Boot CLI
[Link] jackson-datatype- 2.8.10
jsr310
[Link] jackson-datatype- 2.8.10
jsr353
[Link] jackson-datatype- 2.8.10
pcollections
[Link] jackson-jaxrs-base 2.8.10
[Link] jackson-jaxrs-cbor- 2.8.10
provider
[Link] jackson-jaxrs-json- 2.8.10
provider
[Link] jackson-jaxrs-smile- 2.8.10
provider
[Link] jackson-jaxrs-xml- 2.8.10
provider
[Link] jackson-jaxrs-yaml- 2.8.10
provider
[Link] jackson-jr-all 2.8.10
[Link] jackson-jr-objects 2.8.10
[Link] jackson-jr-retrofit2 2.8.10
13
Spring Boot CLI
[Link] jackson-jr-stree 2.8.10
[Link] jackson-module- 2.8.10
afterburner
[Link] jackson-module-guice 2.8.10
[Link] jackson-module-jaxb- 2.8.10
annotations
[Link] jackson-module- 2.8.10
jsonSchema
[Link] jackson-module-kotlin 2.8.10
[Link] jackson-module-mrbean 2.8.10
[Link] jackson-module-osgi 2.8.10
[Link] jackson-module- 2.8.10
parameter-names
[Link] jackson-module- 2.8.10
paranamer
[Link] jackson-module- 2.8.10
scala_2.10
[Link] jackson-module- 2.8.10
scala_2.11
14
Spring Boot CLI
[Link] jackson-module- 2.8.10
scala_2.12
[Link] gemfire 8.2.7
[Link] caffeine 2.3.5
[Link] thymeleaf-extras-data- 1.3
as attribute
[Link] appengine-api-1.0-sdk 1.9.58
[Link] gson 2.8.2
[Link]-simple json-simple 1.1.1
com.h2database h2 1.4.196
[Link] hazelcast 3.7.8
[Link] hazelcast-client 3.7.8
[Link] hazelcast-hibernate4 3.7.1
[Link] hazelcast-hibernate5 1.1.3
[Link] hazelcast-spring 3.7.8
[Link] json-path 2.2.0
15
Spring Boot CLI
[Link] json-path-assert 2.2.0
[Link] mssql-jdbc 6.1.0.jre7
[Link] querydsl-apt 4.1.4
[Link] querydsl-collections 4.1.4
[Link] querydsl-core 4.1.4
[Link] querydsl-jpa 4.1.4
[Link] querydsl-mongodb 4.1.4
[Link] jmustache 1.13
[Link] sendgrid-java 2.2.2
[Link] [Link] 1.5.6
[Link] java-statsd-client 3.1.0
[Link] unboundid-ldapsdk 3.2.1
[Link] HikariCP 2.5.1
[Link] HikariCP-java6 2.3.13
[Link] HikariCP-java7 2.4.13
16
Spring Boot CLI
commons-beanutils commons-beanutils 1.9.3
commons-codec commons-codec 1.10
commons-collections commons-collections 3.2.2
commons-dbcp commons-dbcp 1.4
commons-digester commons-digester 2.1
commons-pool commons-pool 1.6
[Link] [Link].m 1.50.5
ongo
dom4j dom4j 1.6.1
[Link] metrics-annotation 3.1.5
[Link] metrics-core 3.1.5
[Link] metrics-ehcache 3.1.5
[Link] metrics-ganglia 3.1.5
[Link] metrics-graphite 3.1.5
[Link] metrics-healthchecks 3.1.5
17
Spring Boot CLI
[Link] metrics-httpasyncclient 3.1.5
[Link] metrics-jdbi 3.1.5
[Link] metrics-jersey 3.1.5
[Link] metrics-jersey2 3.1.5
[Link] metrics-jetty8 3.1.5
[Link] metrics-jetty9 3.1.5
[Link] metrics-jetty9-legacy 3.1.5
[Link] metrics-json 3.1.5
[Link] metrics-jvm 3.1.5
[Link] metrics-log4j 3.1.5
[Link] metrics-log4j2 3.1.5
[Link] metrics-logback 3.1.5
[Link] metrics-servlet 3.1.5
[Link] metrics-servlets 3.1.5
[Link] reactor-bus [Link]
18
Spring Boot CLI
[Link] reactor-core [Link]
[Link] reactor-groovy [Link]
[Link] reactor-groovy- [Link]
extensions
[Link] reactor-logback [Link]
[Link] reactor-net [Link]
[Link] reactor-stream [Link]
[Link] reactor-spring-context [Link]
[Link] reactor-spring-core [Link]
[Link] reactor-spring- [Link]
messaging
[Link] reactor-spring-webmvc [Link]
[Link] jest 2.0.4
[Link] undertow-core [Link]
[Link] undertow-servlet [Link]
[Link] undertow-websockets- [Link]
jsr
19
Spring Boot CLI
[Link] cache-api 1.0.0
[Link] jms-api 1.1-rev-1
[Link] [Link]-api 1.5.6
[Link] [Link]-api 3.1.0
[Link] jstl 1.2
[Link] [Link]-api 1.2
[Link] validation-api [Link]
jaxen jaxen 1.1.6
joda-time joda-time 2.9.9
junit junit 4.12
mysql mysql-connector-java 5.1.44
[Link] jna 4.2.2
[Link] jna-platform 4.2.2
[Link] ehcache 2.10.4
[Link] htmlunit 2.21
20
Spring Boot CLI
[Link] jtds 1.3.1
[Link] nekohtml 1.9.22
[Link] thymeleaf-layout- 1.4.0
dialect
[Link] activemq-amqp 5.14.5
[Link] activemq-blueprint 5.14.5
[Link] activemq-broker 5.14.5
[Link] activemq-camel 5.14.5
[Link] activemq-client 5.14.5
[Link] activemq-console 5.14.5
[Link] activemq-http 5.14.5
[Link] activemq-jaas 5.14.5
[Link] activemq-jdbc-store 5.14.5
[Link] activemq-jms-pool 5.14.5
[Link] activemq-kahadb-store 5.14.5
21
Spring Boot CLI
[Link] activemq-karaf 5.14.5
[Link] activemq-leveldb-store 5.14.5
[Link] activemq-log4j- 5.14.5
appender
[Link] activemq-mqtt 5.14.5
[Link] activemq-openwire- 5.14.5
generator
[Link] activemq-openwire- 5.14.5
legacy
[Link] activemq-osgi 5.14.5
[Link] activemq-partition 5.14.5
[Link] activemq-pool 5.14.5
[Link] activemq-ra 5.14.5
[Link] activemq-run 5.14.5
[Link] activemq-runtime- 5.14.5
config
[Link] activemq-shiro 5.14.5
[Link] activemq-spring 5.14.5
22
Spring Boot CLI
[Link] activemq-stomp 5.14.5
[Link] activemq-web 5.14.5
[Link] artemis-amqp-protocol 1.5.5
[Link] artemis-commons 1.5.5
[Link] artemis-core-client 1.5.5
[Link] artemis-jms-client 1.5.5
[Link] artemis-jms-server 1.5.5
[Link] artemis-journal 1.5.5
[Link] artemis-native 1.5.5
[Link] artemis-selector 1.5.5
[Link] artemis-server 1.5.5
[Link] artemis-service- 1.5.5
extensions
[Link] commons-dbcp2 2.1.1
[Link] commons-pool2 2.4.2
23
Spring Boot CLI
[Link] derby [Link]
[Link] httpasyncclient 4.1.3
[Link] httpclient 4.5.3
[Link] httpcore 4.4.8
[Link] httpmime 4.5.3
[Link].log4j log4j-1.2-api 2.7
[Link].log4j log4j-api 2.7
[Link].log4j log4j-api-scala_2.10 2.7
[Link].log4j log4j-api-scala_2.11 2.7
[Link].log4j log4j-core 2.7
[Link].log4j log4j-flume-ng 2.7
[Link].log4j log4j-iostreams 2.7
[Link].log4j log4j-jcl 2.7
[Link].log4j log4j-jmx-gui 2.7
[Link].log4j log4j-jul 2.7
24
Spring Boot CLI
[Link].log4j log4j-liquibase 2.7
[Link].log4j log4j-nosql 2.7
[Link].log4j log4j-slf4j-impl 2.7
[Link].log4j log4j-taglib 2.7
[Link].log4j log4j-web 2.7
[Link] solr-analysis-extras 5.5.4
[Link] solr-analytics 5.5.4
[Link] solr-cell 5.5.4
[Link] solr-clustering 5.5.4
[Link] solr-core 5.5.4
[Link] solr-dataimporthandler 5.5.4
[Link] solr-dataimporthandler- 5.5.4
extras
[Link] solr-langid 5.5.4
[Link] solr-map-reduce 5.5.4
25
Spring Boot CLI
[Link] solr-morphlines-cell 5.5.4
[Link] solr-morphlines-core 5.5.4
[Link] solr-solrj 5.5.4
[Link] solr-test-framework 5.5.4
[Link] solr-uima 5.5.4
[Link] solr-velocity 5.5.4
[Link] tomcat-annotations-api 8.5.23
[Link] tomcat-jdbc 8.5.23
[Link] tomcat-jsp-api 8.5.23
[Link] tomcat-embed-core 8.5.23
[Link] tomcat-embed-el 8.5.23
[Link] tomcat-embed-jasper 8.5.23
[Link] tomcat-embed- 8.5.23
websocket
[Link] aspectjrt 1.8.11
26
Spring Boot CLI
[Link] aspectjtools 1.8.11
[Link] aspectjweaver 1.8.11
[Link] assertj-core 2.6.0
[Link] btm 2.1.4
[Link] groovy 2.4.12
[Link] groovy-all 2.4.12
[Link] groovy-ant 2.4.12
[Link] groovy-bsf 2.4.12
[Link] groovy-console 2.4.12
[Link] groovy-docgenerator 2.4.12
[Link] groovy-groovydoc 2.4.12
[Link] groovy-groovysh 2.4.12
[Link] groovy-jmx 2.4.12
[Link] groovy-json 2.4.12
[Link] groovy-jsr223 2.4.12
27
Spring Boot CLI
[Link] groovy-nio 2.4.12
[Link] groovy-servlet 2.4.12
[Link] groovy-sql 2.4.12
[Link] groovy-swing 2.4.12
[Link] groovy-templates 2.4.12
[Link] groovy-test 2.4.12
[Link] groovy-testng 2.4.12
[Link] groovy-xml 2.4.12
[Link] janino 2.7.8
[Link] [Link] 1.3.2
[Link] [Link] 1.3.2
[Link] [Link] 1.3.2
[Link] [Link] 1.3.2
[Link] [Link] 1.3.2
[Link] [Link] 1.3.2
28
Spring Boot CLI
[Link] [Link] 1.3.2
[Link] apache-jsp 9.4.7.v20170914
[Link] apache-jstl 9.4.7.v20170914
[Link] jetty-alpn-client 9.4.7.v20170914
[Link] jetty-alpn-java-client 9.4.7.v20170914
[Link] jetty-alpn-java-server 9.4.7.v20170914
[Link] jetty-alpn-server 9.4.7.v20170914
[Link] jetty-annotations 9.4.7.v20170914
[Link] jetty-ant 9.4.7.v20170914
[Link] jetty-client 9.4.7.v20170914
[Link] jetty-continuation 9.4.7.v20170914
[Link] jetty-deploy 9.4.7.v20170914
[Link] jetty-hazelcast 9.4.7.v20170914
[Link] jetty-http 9.4.7.v20170914
[Link] jetty-http-spi 9.4.7.v20170914
29
Spring Boot CLI
[Link] jetty-infinispan 9.4.7.v20170914
[Link] jetty-io 9.4.7.v20170914
[Link] jetty-jaas 9.4.7.v20170914
[Link] jetty-jaspi 9.4.7.v20170914
[Link] jetty-jmx 9.4.7.v20170914
[Link] jetty-jndi 9.4.7.v20170914
[Link] jetty-nosql 9.4.7.v20170914
[Link] jetty-plus 9.4.7.v20170914
[Link] jetty-proxy 9.4.7.v20170914
[Link] jetty-quickstart 9.4.7.v20170914
[Link] jetty-rewrite 9.4.7.v20170914
[Link] jetty-runner 9.4.7.v20170914
[Link] jetty-security 9.4.7.v20170914
[Link] jetty-server 9.4.7.v20170914
[Link] jetty-servlet 9.4.7.v20170914
30
Spring Boot CLI
[Link] jetty-servlets 9.4.7.v20170914
[Link] jetty-spring 9.4.7.v20170914
[Link] jetty-start 9.4.7.v20170914
[Link] jetty-unixsocket 9.4.7.v20170914
[Link] jetty-util 9.4.7.v20170914
[Link] jetty-util-ajax 9.4.7.v20170914
[Link] jetty-webapp 9.4.7.v20170914
[Link] jetty-xml 9.4.7.v20170914
[Link] cdi-core 9.4.7.v20170914
[Link] cdi-servlet 9.4.7.v20170914
[Link] fcgi-client 9.4.7.v20170914
[Link] fcgi-server 9.4.7.v20170914
[Link] jetty-gcloud-session- 9.4.7.v20170914
manager
[Link].http2 http2-client 9.4.7.v20170914
31
Spring Boot CLI
[Link].http2 http2-common 9.4.7.v20170914
[Link].http2 http2-hpack 9.4.7.v20170914
[Link].http2 http2-http-client- 9.4.7.v20170914
transport
[Link].http2 http2-server 9.4.7.v20170914
[Link] jetty-memcached- 9.4.7.v20170914
sessions
[Link] [Link] 2.2.0.v201112011158
[Link] jetty-httpservice 9.4.7.v20170914
[Link] jetty-osgi-boot 9.4.7.v20170914
[Link] jetty-osgi-boot-jsp 9.4.7.v20170914
[Link] jetty-osgi-boot-warurl 9.4.7.v20170914
[Link] javax-websocket-client- 9.4.7.v20170914
impl
[Link] javax-websocket- 9.4.7.v20170914
server-impl
[Link] websocket-api 9.4.7.v20170914
[Link] websocket-client 9.4.7.v20170914
32
Spring Boot CLI
[Link] websocket-common 9.4.7.v20170914
[Link] websocket-server 9.4.7.v20170914
[Link] websocket-servlet 9.4.7.v20170914
[Link] ehcache 3.2.3
[Link] ehcache-clustered 3.2.3
[Link] ehcache-transactions 3.2.3
[Link] elasticsearch 2.4.6
[Link] jaybird-jdk16 2.2.13
[Link] jaybird-jdk17 2.2.13
[Link] jaybird-jdk18 2.2.13
[Link] flyway-core 3.2.1
[Link] freemarker 2.3.26-incubating
[Link] [Link] 3.0.0
[Link] jersey-guava 2.25.1
ckaged
33
Spring Boot CLI
[Link] jersey-container-servlet 2.25.1
[Link] jersey-container- 2.25.1
servlet-core
[Link] jersey-client 2.25.1
[Link] jersey-common 2.25.1
[Link] jersey-server 2.25.1
[Link] jersey-bean-validation 2.25.1
[Link] jersey-entity-filtering 2.25.1
[Link] jersey-spring3 2.25.1
[Link] jersey-media-jaxb 2.25.1
[Link] jersey-media-json- 2.25.1
jackson
[Link] jersey-media-multipart 2.25.1
[Link] hamcrest-core 1.3
[Link] hamcrest-library 1.3
[Link] hibernate-core [Link]
34
Spring Boot CLI
[Link] hibernate-ehcache [Link]
[Link] hibernate- [Link]
entitymanager
[Link] hibernate-envers [Link]
[Link] hibernate-java8 [Link]
[Link] hibernate-jpamodelgen [Link]
[Link] hibernate-validator [Link]
[Link] hibernate-validator- [Link]
annotation-processor
[Link] hsqldb 2.3.5
[Link] infinispan-jcache [Link]
[Link] infinispan-spring4- [Link]
common
[Link] infinispan-spring4- [Link]
embedded
[Link] javassist 3.21.0-GA
[Link] jboss-transaction-spi [Link]
[Link] jboss-logging [Link]
35
Spring Boot CLI
[Link] jdbc [Link]
[Link] jms [Link]
[Link] jta [Link]
[Link] narayana-jts- [Link]
integration
[Link] jdom2 2.0.6
[Link] jolokia-core 1.3.7
[Link] jooq 3.9.6
[Link] jooq-codegen 3.9.6
[Link] jooq-meta 3.9.6
[Link] json 20140107
[Link] liquibase-core 3.5.3
[Link] mariadb-java-client 1.5.9
[Link] mockito-core 1.10.19
[Link] mongodb-driver 3.4.3
36
Spring Boot CLI
[Link] mongo-java-driver 3.4.3
[Link] apache-el 8.0.33
org.neo4j neo4j-ogm-api 2.1.5
org.neo4j neo4j-ogm-compiler 2.1.5
org.neo4j neo4j-ogm-core 2.1.5
org.neo4j neo4j-ogm-http-driver 2.1.5
[Link] postgresql 9.4.1212.jre7
[Link] lombok 1.16.18
[Link] htmlunit-driver 2.21
[Link] selenium-api 2.53.1
[Link] selenium-chrome-driver 2.53.1
[Link] selenium-firefox-driver 2.53.1
[Link] selenium-ie-driver 2.53.1
[Link] selenium-java 2.53.1
[Link] selenium-remote-driver 2.53.1
37
Spring Boot CLI
[Link] selenium-safari-driver 2.53.1
[Link] selenium-support 2.53.1
[Link] jsonassert 1.4.0
org.slf4j jcl-over-slf4j 1.7.25
org.slf4j jul-to-slf4j 1.7.25
org.slf4j log4j-over-slf4j 1.7.25
org.slf4j slf4j-api 1.7.25
org.slf4j slf4j-ext 1.7.25
org.slf4j slf4j-jcl 1.7.25
org.slf4j slf4j-jdk14 1.7.25
org.slf4j slf4j-log4j12 1.7.25
org.slf4j slf4j-nop 1.7.25
org.slf4j slf4j-simple 1.7.25
[Link] spock-core 1.0-groovy-2.4
[Link] spock-spring 1.0-groovy-2.4
38
Spring Boot CLI
[Link] spring-aop [Link]
[Link] spring-aspects [Link]
[Link] spring-beans [Link]
[Link] spring-context [Link]
[Link] spring-context-support [Link]
[Link] spring-core [Link]
[Link] spring-expression [Link]
[Link] spring-instrument [Link]
[Link] spring-instrument- [Link]
tomcat
[Link] spring-jdbc [Link]
[Link] spring-jms [Link]
[Link] springloaded [Link]
[Link] spring-messaging [Link]
[Link] spring-orm [Link]
39
Spring Boot CLI
[Link] spring-oxm [Link]
[Link] spring-test [Link]
[Link] spring-tx [Link]
[Link] spring-web [Link]
[Link] spring-webmvc [Link]
[Link] spring-webmvc-portlet [Link]
[Link] spring-websocket [Link]
[Link] spring-amqp [Link]
[Link] spring-rabbit [Link]
[Link] spring-batch-core [Link]
[Link] spring-batch- [Link]
infrastructure
[Link] spring-batch-integration [Link]
[Link] spring-batch-test [Link]
[Link] spring-boot [Link]
40
Spring Boot CLI
[Link] spring-boot-actuator [Link]
[Link] spring-boot-actuator- [Link]
docs
[Link] spring-boot- [Link]
autoconfigure
[Link] spring-boot- [Link]
autoconfigure-processor
[Link] spring-boot- [Link]
configuration-metadata
[Link] spring-boot- [Link]
configuration-processor
[Link] spring-boot-devtools [Link]
[Link] spring-boot-loader [Link]
[Link] spring-boot-loader-tools [Link]
[Link] spring-boot-starter [Link]
[Link] spring-boot-starter- [Link]
activemq
[Link] spring-boot-starter- [Link]
actuator
41
Spring Boot CLI
[Link] spring-boot-starter- [Link]
amqp
[Link] spring-boot-starter-aop [Link]
[Link] spring-boot-starter- [Link]
artemis
[Link] spring-boot-starter- [Link]
batch
[Link] spring-boot-starter- [Link]
cache
[Link] spring-boot-starter- [Link]
cloud-connectors
[Link] spring-boot-starter- [Link]
data-cassandra
[Link] spring-boot-starter- [Link]
data-couchbase
[Link] spring-boot-starter- [Link]
data-elasticsearch
[Link] spring-boot-starter- [Link]
data-gemfire
[Link] spring-boot-starter- [Link]
data-jpa
[Link] spring-boot-starter- [Link]
data-ldap
42
Spring Boot CLI
[Link] spring-boot-starter- [Link]
data-mongodb
[Link] spring-boot-starter- [Link]
data-neo4j
[Link] spring-boot-starter- [Link]
data-redis
[Link] spring-boot-starter- [Link]
data-rest
[Link] spring-boot-starter- [Link]
data-solr
[Link] spring-boot-starter- [Link]
freemarker
[Link] spring-boot-starter- [Link]
groovy-templates
[Link] spring-boot-starter- [Link]
hateoas
[Link] spring-boot-starter- [Link]
integration
[Link] spring-boot-starter-jdbc [Link]
[Link] spring-boot-starter- [Link]
jersey
[Link] spring-boot-starter- [Link]
jetty
43
Spring Boot CLI
[Link] spring-boot-starter-jooq [Link]
[Link] spring-boot-starter-jta- [Link]
atomikos
[Link] spring-boot-starter-jta- [Link]
bitronix
[Link] spring-boot-starter-jta- [Link]
narayana
[Link] spring-boot-starter- [Link]
log4j2
[Link] spring-boot-starter- [Link]
logging
[Link] spring-boot-starter-mail [Link]
[Link] spring-boot-starter- [Link]
mobile
[Link] spring-boot-starter- [Link]
mustache
[Link] spring-boot-starter- [Link]
remote-shell
[Link] spring-boot-starter- [Link]
security
[Link] spring-boot-starter- [Link]
social-facebook
44
Spring Boot CLI
[Link] spring-boot-starter- [Link]
social-linkedin
[Link] spring-boot-starter- [Link]
social-twitter
[Link] spring-boot-starter-test [Link]
[Link] spring-boot-starter- [Link]
thymeleaf
[Link] spring-boot-starter- [Link]
tomcat
[Link] spring-boot-starter- [Link]
undertow
[Link] spring-boot-starter- [Link]
validation
[Link] spring-boot-starter-web [Link]
[Link] spring-boot-starter- [Link]
web-services
[Link] spring-boot-starter- [Link]
websocket
[Link] spring-boot-test [Link]
[Link] spring-boot-test- [Link]
autoconfigure
45
Spring Boot CLI
[Link] spring-cloud- [Link]
cloudfoundry-connector
[Link] spring-cloud-core [Link]
[Link] spring-cloud-heroku- [Link]
connector
[Link] spring-cloud- [Link]
localconfig-connector
[Link] spring-cloud-spring- [Link]
service-connector
[Link] spring-cql [Link]
[Link] spring-data-cassandra [Link]
[Link] spring-data-commons [Link]
[Link] spring-data-couchbase [Link]
[Link] spring-data- [Link]
elasticsearch
[Link] spring-data-envers [Link]
[Link] spring-data-gemfire [Link]
[Link] spring-data-jpa [Link]
46
Spring Boot CLI
[Link] spring-data-keyvalue [Link]
[Link] spring-data-ldap [Link]
[Link] spring-data-mongodb [Link]
[Link] spring-data-mongodb- [Link]
cross-store
[Link] spring-data-mongodb- [Link]
log4j
[Link] spring-data-neo4j [Link]
[Link] spring-data-redis [Link]
[Link] spring-data-rest-core [Link]
[Link] spring-data-rest-hal- [Link]
browser
[Link] spring-data-rest- [Link]
webmvc
[Link] spring-data-solr [Link]
[Link] spring-hateoas [Link]
[Link] spring-integration-amqp [Link]
[Link] spring-integration-core [Link]
47
Spring Boot CLI
[Link] spring-integration-event [Link]
[Link] spring-integration-feed [Link]
[Link] spring-integration-file [Link]
[Link] spring-integration-ftp [Link]
[Link] spring-integration- [Link]
gemfire
[Link] spring-integration- [Link]
groovy
[Link] spring-integration-http [Link]
[Link] spring-integration-ip [Link]
[Link] spring-integration-java- [Link]
dsl
[Link] spring-integration-jdbc [Link]
[Link] spring-integration-jms [Link]
[Link] spring-integration-jmx [Link]
[Link] spring-integration-jpa [Link]
[Link] spring-integration-mail [Link]
48
Spring Boot CLI
[Link] spring-integration- [Link]
mongodb
[Link] spring-integration-mqtt [Link]
[Link] spring-integration-redis [Link]
[Link] spring-integration-rmi [Link]
[Link] spring-integration- [Link]
scripting
[Link] spring-integration- [Link]
security
[Link] spring-integration-sftp [Link]
[Link] spring-integration- [Link]
stomp
[Link] spring-integration- [Link]
stream
[Link] spring-integration- [Link]
syslog
[Link] spring-integration-test [Link]
[Link] spring-integration- [Link]
twitter
49
Spring Boot CLI
[Link] spring-integration- [Link]
websocket
[Link] spring-integration-ws [Link]
[Link] spring-integration-xml [Link]
[Link] spring-integration-xmpp [Link]
[Link] spring-integration- [Link]
zookeeper
[Link] spring-kafka [Link]
[Link] spring-kafka-test [Link]
[Link] spring-ldap-core [Link]
[Link] spring-ldap-core-tiger [Link]
[Link] spring-ldap-ldif-batch [Link]
[Link] spring-ldap-ldif-core [Link]
[Link] spring-ldap-odm [Link]
[Link] spring-ldap-test [Link]
[Link] spring-mobile-device [Link]
50
Spring Boot CLI
[Link] spring-plugin-core [Link]
[Link] spring-plugin-metadata [Link]
[Link] spring-restdocs-core [Link]
[Link] spring-restdocs- [Link]
mockmvc
[Link] spring-restdocs- [Link]
restassured
[Link] spring-retry [Link]
[Link] spring-security-acl [Link]
[Link] spring-security-aspects [Link]
[Link] spring-security-cas [Link]
[Link] spring-security-config [Link]
[Link] spring-security-core [Link]
[Link] spring-security-crypto [Link]
[Link] spring-security-data [Link]
[Link] spring-security-jwt [Link]
51
Spring Boot CLI
[Link] spring-security-ldap [Link]
[Link] spring-security- [Link]
messaging
[Link] spring-security-openid [Link]
[Link] spring-security- [Link]
remoting
[Link] spring-security-taglibs [Link]
[Link] spring-security-test [Link]
[Link] spring-security-web [Link]
[Link] spring-security-oauth [Link]
uth
[Link] spring-security-oauth2 [Link]
uth
[Link] spring-session [Link]
[Link] spring-session-data- [Link]
gemfire
[Link] spring-session-data- [Link]
mongo
[Link] spring-session-data- [Link]
redis
52
Spring Boot CLI
[Link] spring-session- [Link]
hazelcast
[Link] spring-session-jdbc [Link]
[Link] spring-social-config [Link]
[Link] spring-social-core [Link]
[Link] spring-social-facebook [Link]
[Link] spring-social-facebook- [Link]
web
[Link] spring-social-linkedin [Link]
[Link] spring-social-security [Link]
[Link] spring-social-twitter [Link]
[Link] spring-social-web [Link]
[Link] spring-ws-core [Link]
[Link] spring-ws-security [Link]
[Link] spring-ws-support [Link]
[Link] spring-ws-test [Link]
53
Spring Boot CLI
[Link] thymeleaf [Link]
[Link] thymeleaf-spring4 [Link]
[Link] thymeleaf-extras- [Link]
conditionalcomments
[Link] thymeleaf-extras- [Link]
java8time
[Link] thymeleaf-extras- [Link]
springsecurity4
[Link] hal-browser 9f96c74
[Link] webjars-locator 0.32-1
[Link] sqlite-jdbc 3.15.1
[Link] snakeyaml 1.17
[Link] jedis 2.9.0
wsdl4j wsdl4j 1.6.3
xml-apis xml-apis 1.4.01
54
6. Spring Boot CLI — Default Statements Spring Boot CLI
In this chapter, we will learn about the Default Statements in Spring Boot CLI. To begin
with, we will learn about the Default Imports.
Default Imports
Spring CLI automatically imports many libraries by default so that explicit imports are not
required. Let us now consider the following groovy script to understand Default Imports.
@RestController
class FirstApplication {
@RequestMapping("/")
String welcome() {
"Welcome to [Link]"
}
}
Here, Spring Boot includes import for @RestController, @RequestMapping annotations by
default. There is no requirement for us to use fully-qualified names. You can check by
running the application.
Type the following command −
E:/Test/> spring run [Link]
The above command will generate the following output on console –
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: ([Link])
...
2017-11-07 [Link].310 INFO 4824 --- [ runner-0]
[Link]
: Started application in 3.405 seconds (JVM running for 7.021)
55
Spring Boot CLI
Automatic Main Method
We are not required to create standard main method for groovy script to initialize a spring
application. It is automatically created for Spring Boot application.
56
7. Spring Boot CLI — Starter Thymeleaf Project Spring Boot CLI
In this chapter, we will learn how to create a sample Thymeleaf-based project to
demonstrate the capabilities of Spring CLI. Follow the below mentioned step to create a
sample project −
Step Description
Create a Folder with a name TestApplication with
1
subfolders templates and static.
Create [Link] in TestApplication folder, [Link] in templates
2
folder, [Link] in static folder as explained below.
3 Compile and run the application to verify the result of the implemented logic.
TestApplication/[Link]
@Controller
@Grab('spring-boot-starter-thymeleaf')
class MessageController {
@RequestMapping("/message")
String getMessage(Model model) {
String message = "Welcome to [Link]!";
[Link]("message", message);
return "message";
}
}
TestApplication/templates/[Link]
<!DOCTYPE HTML>
<html xmlns:th = "[Link]
<head>
<title>Spring Boot CLI Example</title>
57
Spring Boot CLI
<meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"
/>
</head>
<body>
<p th:text = "'Message: ' + ${message}" />
</body>
</html>
TestApplication/static/[Link]
<!DOCTYPE HTML>
<html>
<head>
<title>Spring Boot CLI Example</title>
<meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"
/>
</head>
<body>
<p>Go to <a href = "/msg">Message</a></p>
</body>
</html>
Run the application
To run the application, type the following command –
E:/Test/TestApplication/> spring run *.groovy
Now Spring Boot CLI will come into action, download the required dependencies, run the
embedded tomcat, deploy the application and start it. You can see the following output on
console –
Resolving dependencies.............................
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
58
Spring Boot CLI
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: ([Link])
...
2017-11-08 [Link].300 INFO 8360 --- [ runner-0]
[Link] : Tomcat started on port(s): 8080
(http)
2017-11-08 [Link].305 INFO 8360 --- [ runner-0]
[Link] : Started application in 4.203 seconds
(JVM running for 38.792)
Browse the application in Browser
Our Spring-based REST application is now ready. Open URL "[Link]
and you will see the following output –
Go to Message
Click on the Message link and you will see the following output –
Message: Welcome to [Link]!
Important points
Consider the following points to understand the actions taken by Spring CLI –
The @Grab('spring-boot-starter-thymeleaf') annotation directs CLI to download
spring-boot-starter-thymeleaf [Link] version.
Spring CLI automatically detects the version using its metadata, as we have not
specified any group id or version id here.
Finally after code compilation, deploy the war on a embedded tomcat, start
embedded tomcat server on the default port 8080.
59
8. Spring Boot CLI — Testing Application Spring Boot CLI
In this chapter, we will test the sample project created in Hello World Example Chapter to
demonstrate the testing capabilities of Spring CLI. Follow the steps listed in the table below
to test the sample project −
Steps Description
Create [Link] and [Link] in Testfolder as
1
explained below.
2 Compile and run the application to verify the result of the implemented logic.
FirstApplication/[Link]
@RestController
class FirstApplication {
@RequestMapping("/")
String welcome() {
"Welcome to [Link]"
}
}
FirstApplication/[Link]
class TestFirstApplication {
@Test
void welcomeTest() {
assertEquals("Welcome to [Link]", new
FirstApplication().welcome())
}
}
Run the application
To run the application, type the following command −
60
Spring Boot CLI
E:/Test/FirstApplication/> spring test [Link]
[Link]
Now Spring Boot CLI will come into action, download the required dependencies, compile
the source and test file and unit test the code. The following output will be generated on
console –
Resolving dependencies........................................................
.
Time: 0.457
OK (1 test)
Important points
Consider the following points to understand the actions taken by Spring CLI –
The @Test annotation directs CLI to download JUnit 4.12 version.
Spring CLI automatically detects the version using its metadata, as we have not
specified any dependency.
Finally, after code compilation, test the application.
61
9. Spring Boot CLI — Packaging Application Spring Boot CLI
Spring Boot CLI provides jar command in order to package an application as jar file. Let
us test the sample project created in Starter Thymeleaf Project chapter to demonstrate
the packaging capabilities of Spring CLI.
Follow the steps describe below to package the sample project −
Package the application
To package the application, begin by typing the following command −
E:/Test/TestApplication/> spring jar [Link] *.groovy
Output
The command will print the following output −
E:/Test/TestApplication/> spring jar [Link] *.groovy
Output
Now you can see two new files created in the TestApplication folder.
[Link] − An executable jar file.
[Link] − Original jar file.
Include/Exclude
By default, following directories are included along with their contents −
public
resources
static
templates
META-INF
By default, following directories are excluded along with their contents –
repository
build
target
*.jar files
62
Spring Boot CLI
*.groovy files
Using --include, we can include directories excluded otherwise. Using --exclude, we can
exclude directories included otherwise.
Running the Executable Jar
To run the executable Jar, type the following command −
E:/Test/TestApplication/> java -jar [Link]
The above command will generate the following output on console −
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: ([Link])
...
2017-11-08 [Link].300 INFO 8360 --- [ runner-0]
[Link] : Tomcat started on port(s): 8080
(http)
2017-11-08 [Link].305 INFO 8360 --- [ runner-0]
[Link] : Started application in 4.203 seconds
(JVM running for 38.792)
Browse the application in Browser
Our Spring-based REST application is now ready. Open URL as "[Link]
and you will see the following output –
Go to Message
Click on Message link and you will see the following output −
Message: Welcome to [Link]!
63
10. Spring Boot CLI — Creating Project Spring Boot CLI
Spring Boot CLI can be used to create a new project with maven as default build tool using
init command. Maven will use [Link] service. In the following example, we
will create a web application using thymeleaf. Go to E:\Test folder and type the following
command –
E:/Test> spring init --dependencies = web,thymeleaf [Link]
The above command will generate the following output −
Using service at [Link]
Content saved to [Link]
Create Gradle project
We can create a Gradle based project as well by setting --build as gradle. To understand
this in a better way, consider the example given below. Go to E:\Test folder and type the
following command –
E:/Test> spring init --build = gradle --java-version = 1.8 --dependencies =
web,thymeleaf --packaging = war [Link]
The above command will generate the following output −
Using service at [Link]
Content saved to [Link]
64
11. Spring Boot CLI — Using Shell Spring Boot CLI
Spring Boot CLI provides a Shell interface to run the commands in which we can directly
run the commands as shown below. Go to E:\Test folder and type the following command
−
E:/Test> spring shell
The above command will generate the following output −
?[1mSpring Boot?[m?[2m ([Link])?[m
Hit TAB to complete. Type 'help' and hit RETURN for help, and 'exit' to quit.
Running Commands in Shell
In this section, we will learn how to run commands in Shell. Type the following and see
the output −
version
Spring CLI [Link]
You can press Tab to auto complete the commands and type Exit to finish the shell console.
Testing the application in shell
Let us now learn how to test the application in shell. Type the following line of code and
see the output −
E:\Test\FirstApplication>spring shell
?[1mSpring Boot?[m?[2m ([Link])?[m
Hit TAB to complete. Type 'help' and hit RETURN for help, and 'exit' to quit.
$ test [Link] [Link]
.
Time: 0.347
OK (1 test)
$ exit
E:\Test\FirstApplication>
65