$ brew update
$ brew update
Already up-to-date.
$ brew tap spring-io/tap
$ brew tap spring-io/tap
==> Tapping spring-io/tap
Cloning into '/usr/local/Homebrew/Library/Taps/spring-io/homebrew-tap'...
remote: Enumerating objects: 276, done.
remote: Counting objects: 100% (276/276), done.
remote: Compressing objects: 100% (104/104), done.
remote: Total 276 (delta 85), reused 275 (delta 84), pack-reused 0
Receiving objects: 100% (276/276), 41.06 KiB | 201.00 KiB/s, done.
Resolving deltas: 100% (85/85), done.
Tapped 1 formula (28 files, 77.8KB).
brew search spring
brew search spring
==> Formulae
spring-io/tap/spring-boot ✔ spring-loaded
spring-completion spring-roo
==> Casks
mailspring springtoolsuite
brew install spring-boot
$ brew install spring-boot
==> Installing spring-boot from spring-io/tap
==> Downloading https://repo.spring.io/release/org/springframework/boot/spring-b
######################################################################## 100.0%
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/spring-boot/2.4.2: 7 files, 13.2MB, built in 3 seconds
- 查看当前安装的版本
$ spring --version
Spring CLI v2.4.2
- 测试(编写app.groovy)
$ vim app.groovy
vim创建文件(文件不存在)或者编辑文件(文件存在)app.groovy, 按 i 健进入编辑模式
@RestController
class Test {
@GetMapping("/")
String hello() {
"hello world!"
}
}
编辑完成后按esc键退出编辑模式 按:wq保存并退出
- 运行
$ spring run app.groovy
$ spring run app.groovy
Resolving dependencies...................
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.2)
2021-02-16 10:19:51.018 INFO 20111 --- [ runner-0] o.s.boot.SpringApplication : Starting application using Java 15.0.2 on yanghaoyuandeMacBook-Pro.local with PID 20111 (started by yanghaoyuan in /Users/yanghaoyuan/Documents)
2021-02-16 10:19:51.026 INFO 20111 --- [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (jar:file:/usr/local/Cellar/spring-boot/2.4.2/lib/spring-boot-cli-2.4.2.jar!/BOOT-INF/lib/groovy-2.5.14.jar!/) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
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
2021-02-16 10:19:52.651 INFO 20111 --- [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-02-16 10:19:52.681 INFO 20111 --- [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-16 10:19:52.681 INFO 20111 --- [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-16 10:19:52.737 INFO 20111 --- [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@2d6a9952] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader]
2021-02-16 10:19:52.799 INFO 20111 --- [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-16 10:19:52.799 INFO 20111 --- [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1476 ms
2021-02-16 10:19:53.079 INFO 20111 --- [ runner-0] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-16 10:19:53.643 INFO 20111 --- [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-02-16 10:19:53.670 INFO 20111 --- [ runner-0] o.s.boot.SpringApplication : Started application in 8.463 seconds (JVM running for 34.793)
- 验证输出是否为 hello world!
$ curl http://localhost:8080
或者打开浏览器地址栏输入http://localhost:8080
$ curl http://localhost:8080
hello world!