Spring Boot CLI – Using Shell ”; Previous Next 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 You will see the following output. ←[1mSpring Boot←[m←[2m (v2.6.3)←[m Hit TAB to complete. Type ”help” and hit RETURN for help, and ”exit” to quit. $ Running commands in Shell. Type the following and see the output. version Spring CLI v2.6.3 You can press tab to auto complete the commands and type exit to finish the shell console. Testing the application in shell Type the following and see the output. $ exit E:TestFirstApplication> Print Page Previous Next Advertisements ”;
Category: springbootcli
Spring Boot CLI – Starter Thymeleaf Project ”; Previous Next Let”s 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 1 Create a Folder with a name TestApplication with subfolders templates and static. 2 Create message.groovy in TestApplication folder, message.html in templates folder, index.html in static folder as explained below. 3 Compile and run the application to verify the result of the implemented logic. TestApplication/message.groovy @Controller @Grab(”spring-boot-starter-thymeleaf”) class MessageController { @RequestMapping(“/message”) String getMessage(Model model) { String message = “Welcome to TutorialsPoint.Com!”; model.addAttribute(“message”, message); return “message”; } } TestApplication/templates/message.html <!DOCTYPE HTML> <html xmlns:th=”http://www.thymeleaf.org”> <head> <title>Spring Boot CLI Example</title> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> </head> <body> <p th:text=””Message: ” + ${message}” /> </body> </html> TestApplication/static/index.html <!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=”/message”>Message</a></p> </body> </html> Run the application Type the following command E:/Test/TestApplication/> spring run *.groovy Now Spring Boot CLI will come into action, download required dependencies, run the embedded tomcat, deploy the application and start it. You can see the following output on console. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:36:33.362 INFO 10764 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 10764 (started by intel in E:TestTestApplication) 2022-02-03 11:36:33.372 INFO 10764 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:36:35.743 INFO 10764 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:36:35.768 INFO 10764 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:36:35.769 INFO 10764 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:36:35.829 INFO 10764 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@553a3d88] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:36:35.896 INFO 10764 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:36:35.897 INFO 10764 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2085 ms 2022-02-03 11:36:36.436 INFO 10764 — [ runner-0] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html] 2022-02-03 11:36:37.132 INFO 10764 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:36:37.153 INFO 10764 — [ runner-0] o.s.boot.SpringApplication : Started application in 4.805 seconds (JVM running for 8.633) 2022-02-03 11:37:03.049 INFO 10764 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ”dispatcherServlet” 2022-02-03 11:37:03.049 INFO 10764 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ”dispatcherServlet” 2022-02-03 11:37:03.054 INFO 10764 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms Browse the application in Browser Our spring based rest application is now ready. Open url as “http://localhost:8080/” and you will see the following output. Go to Message Click on Message link and you will see the following output. Message: Welcome to TutorialsPoint.Com! Points to consider Following actions are taken by Spring CLI. @Grab(”spring-boot-starter-thymeleaf”) annotation directs CLI to download spring-boot-starter-thymeleaf 2.6.3 version. Spring CLI automatically detects the version using its metadata as we”ve not specified any group id or version id here. Finally it compiles the code, deploy the war on a embedded tomcat, start embedded tomcat server on the default port 8080. Print Page Previous Next Advertisements ”;
Spring Boot CLI – Useful Resources ”; Previous Next The following resources contain additional information on Spring Boot CLI. Please use them to get more in-depth knowledge on this topic. Useful Links on Spring Boot CLI Spring Boot CLI – Spring Boot CLI Official Home page. Useful Books on Spring Boot CLI To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Spring Boot CLI – Default Statements ”; Previous Next Default Imports Spring CLI automatically imports many libraries by default so that explicit imports are not required. Consider the following groovy script. @RestController class FirstApplication { @RequestMapping(“/”) String welcome() { “Welcome to TutorialsPoint.Com” } } Here import for @RestController, @RequestMapping annotations are already included by default by Spring Boot. We”re not even require to use fully-qualified names. You can check by running the application. Type the following command E:/Test/> spring run FirstApplication.groovy You can see the following output on console. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:29:01.177 INFO 10668 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 10668 (started by intel in F:Test) 2022-02-03 11:29:01.187 INFO 10668 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:29:03.555 INFO 10668 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:29:03.591 INFO 10668 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:29:03.592 INFO 10668 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:29:03.659 INFO 10668 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@8646db9] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:29:03.735 INFO 10668 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:29:03.736 INFO 10668 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2107 ms 2022-02-03 11:29:04.945 INFO 10668 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:29:04.968 INFO 10668 — [ runner-0] o.s.boot.SpringApplication : Started application in 4.811 seconds (JVM running for 8.805) 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. Print Page Previous Next Advertisements ”;
“grab” Co-ordinates Deduction ”; Previous Next We can specify a dependency using @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 2.6.3 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 efault dependency metadata without declaring a version, the version listed in its table will be used. Following table shows all the dependencies and their versions included in the default metadata for Spring Boot CLI 2.6.3 version. Group Id Artifact Id Version antlr antlr 2.7.7 ch.qos.logback logback-access 1.2.10 ch.qos.logback logback-classic 1.2.10 ch.qos.logback logback-core 1.2.10 com.atomikos transactions-jdbc 4.0.6 com.atomikos transactions-jms 4.0.6 com.atomikos transactions-jta 4.0.6 com.couchbase.client java-client 3.2.4 com.datastax.oss java-driver-core 4.13.0 com.datastax.oss java-driver-core-shaded 4.13.0 com.datastax.oss java-driver-mapper-processor 4.13.0 com.datastax.oss java-driver-mapper-runtime 4.13.0 com.datastax.oss java-driver-metrics-micrometer 4.13.0 com.datastax.oss java-driver-metrics-microprofile 4.13.0 com.datastax.oss java-driver-query-builder 4.13.0 com.datastax.oss java-driver-shaded-guava 25.1-jre-graal-sub-1 com.datastax.oss java-driver-test-infra 4.13.0 com.datastax.oss native-protocol 1.5.0 com.fasterxml classmate 1.5.1 com.fasterxml.jackson.core jackson-annotations 2.13.1 com.fasterxml.jackson.core jackson-core 2.13.1 com.fasterxml.jackson.core jackson-databind 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-avro 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-cbor 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-csv 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-ion 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-properties 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-protobuf 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-smile 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-toml 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-xml 2.13.1 com.fasterxml.jackson.dataformat jackson-dataformat-yaml 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-eclipse-collections 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-guava 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hibernate4 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hibernate5 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hibernate5-jakarta 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-hppc 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jakarta-jsonp 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jaxrs 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jdk8 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-joda 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-joda-money 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-json-org 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jsr310 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jsr353 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-pcollections 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-base 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-cbor-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-json-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-smile-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-xml-provider 2.13.1 com.fasterxml.jackson.jakarta.rs jackson-jakarta-rs-yaml-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-base 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-cbor-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-smile-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-xml-provider 2.13.1 com.fasterxml.jackson.jaxrs jackson-jaxrs-yaml-provider 2.13.1 com.fasterxml.jackson.jr jackson-jr-all 2.13.1 com.fasterxml.jackson.jr jackson-jr-annotation-support 2.13.1 com.fasterxml.jackson.jr jackson-jr-objects 2.13.1 com.fasterxml.jackson.jr jackson-jr-retrofit2 2.13.1 com.fasterxml.jackson.jr jackson-jr-stree 2.13.1 com.fasterxml.jackson.module jackson-module-afterburner 2.13.1 com.fasterxml.jackson.module jackson-module-blackbird 2.13.1 com.fasterxml.jackson.module jackson-module-guice 2.13.1 com.fasterxml.jackson.module jackson-module-jakarta-xmlbind-annotations 2.13.1 com.fasterxml.jackson.module jackson-module-jaxb-annotations 2.13.1 com.fasterxml.jackson.module jackson-module-jsonSchema 2.13.1 com.fasterxml.jackson.module jackson-module-kotlin 2.13.1 com.fasterxml.jackson.module jackson-module-mrbean 2.13.1 com.fasterxml.jackson.module jackson-module-no-ctor-deser 2.13.1 com.fasterxml.jackson.module jackson-module-osgi 2.13.1 com.fasterxml.jackson.module jackson-module-parameter-names 2.13.1 com.fasterxml.jackson.module jackson-module-paranamer 2.13.1 com.fasterxml.jackson.module jackson-module-scala_2.11 2.13.1 com.fasterxml.jackson.module jackson-module-scala_2.12 2.13.1 com.fasterxml.jackson.module jackson-module-scala_2.13 2.13.1 com.fasterxml.jackson.module jackson-module-scala_3 2.13.1 com.github.ben-manes.caffeine caffeine 2.9.3 com.github.ben-manes.caffeine guava 2.9.3 com.github.ben-manes.caffeine jcache 2.9.3 com.github.ben-manes.caffeine simulator 2.9.3 com.github.mxab.thymeleaf.extras thymeleaf-extras-data-attribute 2.0.1 com.google.appengine appengine-api-1.0-sdk 1.9.93 com.google.cloud cloud-spanner-r2dbc 1.1.0 com.google.code.gson gson 2.8.9 com.h2database h2 1.4.200 com.hazelcast hazelcast 4.2.4 com.hazelcast hazelcast-hibernate52 2.2.1 com.hazelcast hazelcast-hibernate53 2.2.1 com.hazelcast hazelcast-spring 4.2.4 com.ibm.db2 jcc 11.5.7.0 com.jayway.jsonpath json-path 2.6.0 com.jayway.jsonpath json-path-assert 2.6.0 com.microsoft.sqlserver mssql-jdbc 9.4.1.jre8 com.oracle.database.ha ons 21.3.0.0 com.oracle.database.ha simplefan 21.3.0.0 com.oracle.database.jdbc ojdbc11 21.3.0.0 com.oracle.database.jdbc ojdbc11-production 21.3.0.0 com.oracle.database.jdbc ojdbc8 21.3.0.0 com.oracle.database.jdbc ojdbc8-production 21.3.0.0 com.oracle.database.jdbc rsi 21.3.0.0 com.oracle.database.jdbc ucp 21.3.0.0 com.oracle.database.jdbc ucp11 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11-observability-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11_g 21.3.0.0 com.oracle.database.jdbc.debug ojdbc11dms_g 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8-observability-debug 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8_g 21.3.0.0 com.oracle.database.jdbc.debug ojdbc8dms_g 21.3.0.0 com.oracle.database.nls orai18n 21.3.0.0 com.oracle.database.observability dms 21.3.0.0 com.oracle.database.observability ojdbc11-observability 21.3.0.0 com.oracle.database.observability ojdbc11dms 21.3.0.0 com.oracle.database.observability ojdbc8-observability 21.3.0.0 com.oracle.database.observability ojdbc8dms 21.3.0.0 com.oracle.database.r2dbc oracle-r2dbc 0.1.0 com.oracle.database.security oraclepki 21.3.0.0 com.oracle.database.security osdt_cert 21.3.0.0 com.oracle.database.security osdt_core 21.3.0.0 com.oracle.database.xml xdb 21.3.0.0 com.oracle.database.xml xmlparserv2 21.3.0.0 com.querydsl querydsl-apt 5.0.0 com.querydsl querydsl-codegen 5.0.0 com.querydsl querydsl-codegen-utils 5.0.0 com.querydsl querydsl-collections 5.0.0 com.querydsl querydsl-core 5.0.0 com.querydsl querydsl-guava 5.0.0 com.querydsl querydsl-hibernate-search 5.0.0 com.querydsl querydsl-jdo 5.0.0 com.querydsl querydsl-jpa 5.0.0 com.querydsl querydsl-jpa-codegen 5.0.0 com.querydsl querydsl-kotlin 5.0.0 com.querydsl querydsl-kotlin-codegen 5.0.0 com.querydsl querydsl-lucene3 5.0.0 com.querydsl querydsl-lucene4 5.0.0 com.querydsl querydsl-lucene5 5.0.0 com.querydsl querydsl-mongodb 5.0.0 com.querydsl querydsl-scala 5.0.0 com.querydsl querydsl-spatial 5.0.0 com.querydsl querydsl-sql 5.0.0 com.querydsl querydsl-sql-codegen 5.0.0 com.querydsl querydsl-sql-spatial 5.0.0 com.querydsl querydsl-sql-spring 5.0.0 com.rabbitmq amqp-client 5.13.1 com.rabbitmq stream-client 0.4.0 com.samskivert jmustache 1.15 com.sendgrid sendgrid-java 4.7.6 com.squareup.okhttp3 logging-interceptor 3.14.9 com.squareup.okhttp3 mockwebserver 3.14.9 com.squareup.okhttp3 okcurl 3.14.9 com.squareup.okhttp3 okhttp 3.14.9 com.squareup.okhttp3 okhttp-dnsoverhttps 3.14.9 com.squareup.okhttp3 okhttp-sse 3.14.9 com.squareup.okhttp3 okhttp-testing-support 3.14.9 com.squareup.okhttp3 okhttp-tls 3.14.9 com.squareup.okhttp3 okhttp-urlconnection 3.14.9 com.sun.activation jakarta.activation 1.2.2 com.sun.mail jakarta.mail 1.6.7 com.sun.xml.messaging.saaj saaj-impl 1.5.3 com.unboundid unboundid-ldapsdk 4.0.14 com.zaxxer HikariCP 4.0.3 commons-codec commons-codec 1.15 commons-pool commons-pool 1.6 de.flapdoodle.embed de.flapdoodle.embed.mongo 3.0.0 dev.miku r2dbc-mysql 0.8.2.RELEASE io.dropwizard.metrics metrics-annotation 4.2.7 io.dropwizard.metrics metrics-caffeine 4.2.7 io.dropwizard.metrics metrics-caffeine3 4.2.7 io.dropwizard.metrics metrics-collectd 4.2.7 io.dropwizard.metrics metrics-core 4.2.7 io.dropwizard.metrics metrics-ehcache 4.2.7 io.dropwizard.metrics metrics-graphite 4.2.7 io.dropwizard.metrics metrics-healthchecks 4.2.7 io.dropwizard.metrics metrics-httpasyncclient 4.2.7 io.dropwizard.metrics metrics-httpclient 4.2.7 io.dropwizard.metrics metrics-httpclient5 4.2.7 io.dropwizard.metrics metrics-jakarta-servlet 4.2.7 io.dropwizard.metrics metrics-jakarta-servlets 4.2.7 io.dropwizard.metrics metrics-jcache 4.2.7 io.dropwizard.metrics metrics-jdbi 4.2.7 io.dropwizard.metrics metrics-jdbi3 4.2.7 io.dropwizard.metrics metrics-jersey2 4.2.7 io.dropwizard.metrics metrics-jersey3 4.2.7 io.dropwizard.metrics metrics-jetty10 4.2.7 io.dropwizard.metrics metrics-jetty11 4.2.7 io.dropwizard.metrics metrics-jetty9 4.2.7 io.dropwizard.metrics metrics-jmx 4.2.7 io.dropwizard.metrics metrics-json 4.2.7 io.dropwizard.metrics metrics-jvm 4.2.7 io.dropwizard.metrics metrics-log4j2 4.2.7 io.dropwizard.metrics metrics-logback 4.2.7 io.dropwizard.metrics metrics-servlet 4.2.7 io.dropwizard.metrics metrics-servlets 4.2.7 io.lettuce lettuce-core 6.1.6.RELEASE io.micrometer micrometer-core 1.8.2 io.micrometer micrometer-jersey2 1.8.2 io.micrometer micrometer-registry-appoptics 1.8.2 io.micrometer micrometer-registry-atlas 1.8.2 io.micrometer micrometer-registry-azure-monitor 1.8.2 io.micrometer micrometer-registry-cloudwatch 1.8.2 io.micrometer micrometer-registry-cloudwatch2 1.8.2 io.micrometer micrometer-registry-datadog 1.8.2 io.micrometer micrometer-registry-dynatrace 1.8.2 io.micrometer micrometer-registry-elastic 1.8.2 io.micrometer micrometer-registry-ganglia 1.8.2 io.micrometer micrometer-registry-graphite 1.8.2 io.micrometer micrometer-registry-health 1.8.2 io.micrometer micrometer-registry-humio 1.8.2 io.micrometer micrometer-registry-influx 1.8.2 io.micrometer micrometer-registry-jmx 1.8.2 io.micrometer micrometer-registry-kairos 1.8.2
Spring Boot CLI – Discussion
Discuss Spring Boot CLI ”; Previous Next 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. Print Page Previous Next Advertisements ”;
Spring Boot CLI – Quick Guide ”; Previous Next Spring Boot CLI – Overview 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 CL − It provides an interface to run and test Spring Boot Application from command prompt. It internally use Spring Boot Starter and Spring Boot AutoConfigurate components in order to resolve all dependencies and executes 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. Spring Boot CLI – Environment Setup 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:jdk-11.0.11, you would have to put the following line in your C:autoexec.bat file. set PATH=C:jdk-11.0.11;%PATH% set JAVA_HOME=C:jdk-11.0.11 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/jdk-11.0.11 and you use the C shell, you will have to put the following into your .cshrc file. setenv PATH /usr/local/jdk-11.0.11/bin:$PATH setenv JAVA_HOME /usr/local/jdk-11.0.11 Step 2 – Install Spring Boot CLI You can download the latest version of Spring Boot CLI API as ZIP archive from https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/. Once you download the installation, unpack the zip distribution into a convenient location. For example, in E:Testspring-boot-cli-2.6.3 on Windows, or /usr/local/spring-boot-cli-2.6.3 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:Testspring-boot-cli-2.6.3-binspring-2.6.3bin;%PATH% Step 3 – Verify installation Run the following command on command prompt to verify the installation − E:/Test/> spring –version It should print the following output confirming the successful installation − Spring CLI v2.6.3 Spring Boot CLI – Hello World Example In this example, we”ll 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 FirstApplication.groovy file in E:Test folder with following source code. @RestController class FirstApplication { @RequestMapping(“/”) String welcome() { “Welcome to TutorialsPoint.Com” } } Step 3: Run the application Type the following command E:/Test/> spring run FirstApplication.groovy Now Spring Boot CLI will come into action, download required dependencies, run the embedded tomcat, deploy the application and start it. You can see the following output on console. E:Test>spring run FirstApplication.groovy Resolving dependencies…………………………. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:12:42.683 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 6956 (started by intel in F:Test) 2022-02-03 11:12:42.710 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:12:45.110 INFO 6956 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:12:45.138 INFO 6956 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:12:45.139 INFO 6956 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:12:45.229 INFO 6956 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@8646db9] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:12:45.333 INFO 6956 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:12:45.333 INFO 6956 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2124 ms 2022-02-03 11:12:46.901 INFO 6956 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:12:46.930 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : Started application in 5.416 seconds (JVM running for 49.049) 2022-02-03 11:13:48.910 INFO 6956 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ”dispatcherServlet” 2022-02-03 11:13:48.912 INFO 6956 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ”dispatcherServlet” 2022-02-03 11:13:48.915 INFO 6956 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms Step 4: Browse the application in Browser Our spring based rest application is now ready. Open url as “http://localhost:8080/” and you will see the following output. Welcome to TutorialsPoint.Com Points to consider Following actions are taken by Spring CLI. All dependency JARs are downloaded for the first time only. Spring CLI automatically detects which dependency JARs are to be downloaded based on the classes and annotations used in code. Finally it compiles the code, deploy the war on a embedded tomcat, start embedded tomcat server on the default port 8080. “grab”
Spring Boot CLI – Hello World Example ”; Previous Next In this example, we”ll 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 FirstApplication.groovy file in E:Test folder with following source code. @RestController class FirstApplication { @RequestMapping(“/”) String welcome() { “Welcome to TutorialsPoint.Com” } } Step 3: Run the application Type the following command E:/Test/> spring run FirstApplication.groovy Now Spring Boot CLI will come into action, download required dependencies, run the embedded tomcat, deploy the application and start it. You can see the following output on console. E:Test>spring run FirstApplication.groovy Resolving dependencies…………………………. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:12:42.683 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 6956 (started by intel in F:Test) 2022-02-03 11:12:42.710 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:12:45.110 INFO 6956 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:12:45.138 INFO 6956 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:12:45.139 INFO 6956 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:12:45.229 INFO 6956 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@8646db9] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:12:45.333 INFO 6956 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:12:45.333 INFO 6956 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2124 ms 2022-02-03 11:12:46.901 INFO 6956 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:12:46.930 INFO 6956 — [ runner-0] o.s.boot.SpringApplication : Started application in 5.416 seconds (JVM running for 49.049) 2022-02-03 11:13:48.910 INFO 6956 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ”dispatcherServlet” 2022-02-03 11:13:48.912 INFO 6956 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ”dispatcherServlet” 2022-02-03 11:13:48.915 INFO 6956 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms Step 4: Browse the application in Browser Our spring based rest application is now ready. Open url as “http://localhost:8080/” and you will see the following output. Welcome to TutorialsPoint.Com Points to consider Following actions are taken by Spring CLI. All dependency JARs are downloaded for the first time only. Spring CLI automatically detects which dependency JARs are to be downloaded based on the classes and annotations used in code. Finally it compiles the code, deploy the war on a embedded tomcat, start embedded tomcat server on the default port 8080. Print Page Previous Next Advertisements ”;
“grab” Dependency Deduction ”; Previous Next Standard Groovy codebase contains a @Grab annotation so that dependencies on third-party libraries can be declared. Using @Grab annotation, 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 Following table details the hints that Spring Boot uses to download third party libraries − Sr.No. Hint & Dependency to Download/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 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 Print Page Previous Next Advertisements ”;
Spring Boot CLI – Home
Spring Boot CLI Tutorial PDF Version Quick Guide Resources Job Search Discussion 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 Spring Tutorial is the only prerequisite for learning the concepts explained in this tutorial. Print Page Previous Next Advertisements ”;