![]() |
Once you have installed the CLI, you can run it by typing $ spring
usage: spring [--help] [--version]
<command> [<args>]
Available commands are:
run [options] <files> [--] [args]
Run a spring groovy script
... more command help is shown here You can type $ spring help run spring run - Run a spring groovy script usage: spring run [options] <files> [--] [args] Option Description ------ ----------- --autoconfigure [Boolean] Add autoconfigure compiler transformations (default: true) --classpath, -cp Additional classpath entries -e, --edit Open the file with the default system editor --no-guess-dependencies Do not attempt to guess dependencies --no-guess-imports Do not attempt to guess imports -q, --quiet Quiet logging -v, --verbose Verbose logging of dependency resolution --watch Watch the specified file for changes The $ spring version Spring CLI v2.0.5.RELEASE You can compile and run Groovy source code by using the The following example shows a “hello world” web application written in Groovy: hello.groovy. @RestController class WebApplication { @RequestMapping("/") String home() { "Hello World!" } }
To compile and run the application, type the following command: $ spring run hello.groovy To pass command-line arguments to the application, use $ spring run hello.groovy -- --server.port=9000 To set JVM command line arguments, you can use the $ JAVA_OPTS=-Xmx1024m spring run hello.groovy
Standard Groovy includes a Spring Boot extends this technique further and tries to deduce which libraries to “grab”
based on your code. For example, since the The following items are used as “grab hints”:
Spring Boot extends Groovy’s standard
To help reduce the size of your Groovy code, several
Unlike the equivalent Java application, you do not need to include a
By default, the CLI uses the dependency management declared in For example, consider the following declaration: @DependencyManagementBom("com.example.custom-bom:1.0.0") The preceding declaration picks up When you specify multiple BOMs, they are applied in the order in which you declare them, as shown in the following example: @DependencyManagementBom(["com.example.custom-bom:1.0.0", "com.example.another-bom:1.0.0"]) The preceding example indicates that the dependency management in You can use @DependencyManagementBom('io.spring.platform:platform-bom:1.1.2.RELEASE') You can use “shell globbing” with all commands that accept file input. Doing so lets you use multiple files from a single directory, as shown in the following example: $ spring run *.groovy You can use the $ spring jar my-app.jar *.groovy The resulting jar contains the classes produced by compiling the application and all of
the application’s dependencies so that it can then be run by using public/**, resources/**, static/**, templates/**, META-INF/**, * The default excludes are as follows: .*, repository/**, build/**, target/**, **/*.jar, **/*.groovy Type The $ spring init --dependencies=web,data-jpa my-project Using service at https://start.spring.io Project extracted to '/Users/developer/example/my-project' The preceding example creates a $ spring init --list ======================================= Capabilities of https://start.spring.io ======================================= Available dependencies: ----------------------- actuator - Actuator: Production ready features to help you monitor and manage your application ... web - Web: Support for full-stack web development, including Tomcat and spring-webmvc websocket - Websocket: Support for WebSocket development ws - WS: Support for Spring Web Services Available project types: ------------------------ gradle-build - Gradle Config [format:build, build:gradle] gradle-project - Gradle Project [format:project, build:gradle] maven-build - Maven POM [format:build, build:maven] maven-project - Maven Project [format:project, build:maven] (default) ... The $ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip Using service at https://start.spring.io Content saved to 'sample-app.zip' Spring Boot includes command-line completion scripts for the BASH and zsh shells. If you
do not use either of these shells (perhaps you are a Windows user), you can use the
$ spring shell
Spring Boot (v2.0.5.RELEASE)
Hit TAB to complete. Type \'help' and hit RETURN for help, and \'exit' to quit. From inside the embedded shell, you can run other commands directly: $ version Spring CLI v2.0.5.RELEASE The embedded shell supports ANSI color output as well as You can add extensions to the CLI by using the $ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE In addition to installing the artifacts identified by the coordinates you supply, all of the artifacts' dependencies are also installed. To uninstall a dependency, use the $ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE It uninstalls the artifacts identified by the coordinates you supply and their dependencies. To uninstall all additional dependencies, you can use the $ spring uninstall --all
|