Spring Boot CLI - ncrash/programming-note GitHub Wiki

Spring-boot CLI

Spring-boot CLI μ†Œκ°œ

  • μŠ€ν”„λ§μ„ μ΄μš©ν•΄ λΉ λ₯΄κ²Œ κ°„νŽΈν•˜κ²Œ ν”„λ‘œν† νƒ€μ΄ν•‘μ„ λ§Œλ“€μ–΄ λ³Ό 수 있게 λ„μ™€μ£ΌλŠ” μ»€λ§¨λ“œλΌμΈ 툴
    • spring-boot-cli/samples/ νŽ˜μ΄μ§€μ—μ„œ λ‹€μ–‘ν•œ 예제λ₯Ό λ§Œλ‚˜λ³Ό 수 있음
  • Groovy 슀크립트으둜만 ν”„λ‘œκ·Έλž˜λ° κ°€λŠ₯
  • μžλ°” 1.6버전 μ΄μƒμ˜ ν•„μš”
  • zsh/bash μžλ™μ™„μ„± κΈ°λŠ₯지원

μžλ™μ™„μ„± ν™œμš©μ˜ˆ

$ spring <TAB>
encodepassword  -- Encode a password for use with Spring Security
grab            -- Download a spring groovy script's dependencies to ./repository
help            -- Get help on commands
init            -- Initialize a new project using Spring Initializr (start.spring.io)
install         -- Install dependencies to the lib/ext directory
jar             -- Create a self-contained executable jar file from a Spring Groovy script
run             -- Run a spring groovy script
shell           -- Start a nested shell
uninstall       -- Uninstall dependencies from the lib/ext directory
version         -- Show the version
war             -- Create a self-contained executable war file from a Spring Groovy script

Spring-boot CLI μ„€μΉ˜

$ brew update
$ brew tap pivotal/tap
$ brew install springboot
  • macOS만 κΈ°μž¬ν•΄λ’€λŠ”λ° Windows μ„€μΉ˜λŠ” JournalDev λΈ”λ‘œκ·Έ 에 친절히 μ„€λͺ…λ˜μ–΄ 있음

Spring-boot CLI ν™œμš©μ˜ˆ

BCrypt μ•”ν˜Έν™”

$ spring encodepassword "helloworld"
{bcrypt}$2a$10$4tdL/kPzseCki6gj.i9CSe6Azyg7xE3oKqTucjbf5dy6xLS2uTWb6

Web

hello.groovy

@RestController
class WebApplication {

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

}

Web μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ‹€ν–‰

$ spring run hello.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (jar:file:/usr/local/Cellar/springboot/2.2.1.RELEASE/lib/spring-boot-cli-2.2.1.RELEASE.jar!/BOOT-INF/lib/groovy-2.5.8.jar!/) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.1.RELEASE)

2020-03-06 23:33:18.239  INFO 65352 --- [       runner-0] o.s.boot.SpringApplication               : Starting application on 01L0217075471DD with PID 65352 (started by daekwon.kang in /Users/daekwon.kang/Code/mine/temp)
2020-03-06 23:33:18.248  INFO 65352 --- [       runner-0] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2020-03-06 23:33:19.271  INFO 65352 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-03-06 23:33:19.290  INFO 65352 --- [       runner-0] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-06 23:33:19.290  INFO 65352 --- [       runner-0] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2020-03-06 23:33:19.341  INFO 65352 --- [       runner-0] org.apache.catalina.loader.WebappLoader  : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@1bc6a36e] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader]
2020-03-06 23:33:19.388  INFO 65352 --- [       runner-0] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-03-06 23:33:19.388  INFO 65352 --- [       runner-0] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 976 ms
2020-03-06 23:33:19.577  INFO 65352 --- [       runner-0] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-06 23:33:19.942  INFO 65352 --- [       runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-06 23:33:19.946  INFO 65352 --- [       runner-0] o.s.boot.SpringApplication               : Started application in 2.358 seconds (JVM running for 4.514)
2020-03-06 23:34:00.558  INFO 65352 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-06 23:34:00.558  INFO 65352 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-03-06 23:34:00.570  INFO 65352 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 12 ms

Web μ• ν”Œλ¦¬μΌ€μ΄μ…˜ ν…ŒμŠ€νŠΈ

$ curl localhost:8080
Hello World!

Reference

⚠️ **GitHub.com Fallback** ⚠️