Spring Boot CLI——centos7

Spring Boot is a command-line tool for rapid prototyping with Spring to build. It allows you to run Groovy scripts, which means you can use the Java-like syntax, and not so much the template code.

All versions Download
here to download the version of spring-boot-cli-2.2.0.BUILD- 20190222.193142-143-bin.tar.gz

Once downloaded unzip

tar   spring-boot-cli-2.2.0.BUILD-20190222.193142-143-bin.tar.gz  -C  /home/maxzhao/
cd /home/maxzhao
mv spring-2.2.0.BUILD-SNAPSHOT  spring-2.2.0-cli
cd spring-2.2.0-cli 

There INSTALL.txt files in the current directory, there is a specific installation methods.
INSTALL.txt document said very clearly, spring-boot-cli-2.2.0 requires JDK1.8 +

Environment variable configuration:

Administrators at # 
# the SET springboot - cli 
vim / etc / Profile 
# finally entered 
Export SPRING_HOME = " /home/maxzhao/soft/spring-2.2.0-cli " 
Export the PATH = " $ SPRING_HOME / bin: $ the PATH " 
# save 
Source / etc / Profile 
the Spring - Version 
. # the Spring CLI v2 2.0 .BUILD- SNAPSHOT

Springboot-cli simple example

 

Run Groovy scripts

After completing the installation Spring Boot CLI, we try to use it to quickly build a Spring Boot application, the method is very simple, just do the following:

Step one: Create a Groovy script, hello.groovywhich reads as follows:

@RestController
class ThisWillActuallyRun {

    @RequestMapping("/")
    String home() {
        "Hello World!"
    }
    
}

Step 2: Use springthe command to run the Groovy script, as follows:

$ spring run hello.groovy
Resolving dependencies...............................................




                                *::::::::::::::*
                           ::::::::::::::::::::::::::
                        ::::::::::::::::::::::::::::::::       :.
                     *:::::::::::::::::::::::::::::::::::::   :*:
                   :::::::::::::::::::::::::::::::::::::::::::  *:
                 .::::::::::::::::::::::::::::::::::::::::::     :
                ::::::::::::::::::::::::::::::::::::::::::.      .:
               :::::::::::::::::::::::::::::::::::::::::          :
              ::::::::::::::::::::::::::::::::::::::              *:
             :::::::::::::::::::::::::::::::::*                    :
            :::::::::::::::::::*                                   :
            :::::::::::::::                                 *      *:
           .::::::::::::                                   *       .:
           :::::::::::.                                   :         :
           ::::::::::                                    :         .:
           ::::::::::                                  ::          .:
           .::::::::                                 :::           :*
            ::::::::                               :::             :
            ::::::::                            ::::              ::
             :::::::                         :::::               *:
              :::::::                   *:::::::                ::
               :::::::.          :::::::::::                  :::
                :::::::::::::::::::::::*                    ::::
                 .:::   :::::::::*                      .:::::*
                   :     ::::::::::::::::::::::::::::::::::::
                     . .:::::::::::::::::::::::::::::::::::
                        ::::::::::::::::::::::::::::::::
                           ::::::::::::::::::::::::::
                                *::::::::::::::*



2018-04-04 18:11:20.571  INFO 70477 --- [       runner-0] o.s.boot.SpringApplication               : Starting application on zhaiyongchaodeMacBook-Pro.local with PID 70477 (started by zhaiyongchao in /Users/zhaiyongchao/Downloads)
2018-04-04 18:11:20.574  INFO 70477 --- [       runner-0] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-04-04 18:11:20.732  INFO 70477 --- [       runner-0] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3c3ad454: startup date [Wed Apr 04 18:11:20 CST 2018]; root of context hierarchy
2018-04-04 18:11:21.758  INFO 70477 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-04-04 18:11:21.783  INFO 70477 --- [       runner-0] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-04-04 18:11:21.784  INFO 70477 --- [       runner-0] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-04-04 18:11:21.795  INFO 70477 --- [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: [/Users/zhaiyongchao/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-04-04 18:11:21.849  INFO 70477 --- [ost-startStop-1] org.apache.catalina.loader.WebappLoader  : Unknown loader org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@5e3b901 class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
2018-04-04 18:11:21.884  INFO 70477 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-04-04 18:11:21.885  INFO 70477 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1153 ms
2018-04-04 18:11:22.042  INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-04-04 18:11:22.049  INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-04-04 18:11:22.049  INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-04-04 18:11:22.049  INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-04-04 18:11:22.049  INFO 70477 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-04-04 18:11:22.391  INFO 70477 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3c3ad454: startup date [Wed Apr 04 18:11:20 CST 2018]; root of context hierarchy
2018-04-04 18:11:22.489  INFO 70477 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String ThisWillActuallyRun.home()
2018-04-04 18:11:22.495  INFO 70477 --- [       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-04-04 18:11:22.496  INFO 70477 --- [       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-04-04 18:11:22.550  INFO 70477 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-04-04 18:11:22.550  INFO 70477 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-04-04 18:11:22.598  INFO 70477 --- [       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-04-04 18:11:22.955  INFO 70477 --- [       runner-0] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-04-04 18:11:23.004  INFO 70477 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-04-04 18:11:23.010  INFO 70477 --- [       runner-0] o.s.boot.SpringApplication

From the log, we can see a simple web application by Groovy script defines us build on the success, you can access localhost:8080to verify the above application interfaces provided by:

$ curl localhost:8080
Hello World!

Can be added in the command springconfiguration parameters, need to pay more attention to a--

$ spring run hello.groovy -- --server.port=9000

To set the JVM parameters, you can use JAVA_OPTSenvironment variables, such as:

$ JAVA_OPTS=-Xmx1024m spring run hello.groovy

Initialize a new project

Use initcommand to create a new project. Such as:

$ spring init --dependencies=web,data-jpa my-project

This command creates a named my-projectdirectory, which contains an in-based Mavenproject, and add to spring-boot-starter-weband spring-boot-starter-data-jpadependent.

You can use the --listtag to display all available dependencies.

$ spring init --list

Run spring help initcan see the specific instructions for use.

The following command creates a basis Gradleand java8packaging type warof project.

$ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip

Use Spring Shell

Spring Boot CLI built a shell, the implementation spring shellcan start. The shell supports ANSI color output and tabkey, if you want to perform native command, the command with !the prefix can be. More specific use, you can enter into the shell helpview.

more info

You can here find more groovy scripts example, where there are documents related to Spring Build tool plugins.

Guess you like

Origin www.cnblogs.com/wpcnblog/p/11517543.html