micronaut入門
micronaut
- https://micronaut.io/index.html
- JVMベースのフルスタックフレームワーク
- Java Groovy Kotlin をサポートしているみたい
- とにかく高速で起動できて、メモリ消費率がかなり少ないみたい
入門
- 公式Docを見ながら入門してみる
- SDKMANで簡単にinstallできるらしいので、SDKMANを使う
$ sdk install micronaut Downloading: micronaut 1.3.4 In progress... ############################################################################################################################################################################## 100.0%############################################################################################################################################################################## 100.0% Installing: micronaut 1.3.4 Done installing! Setting micronaut 1.3.4 as default.
project作成
$mn create-app hello-world
- 起動してみる。めちゃくちゃ起動早い
$ ./gradlew run Downloading https://services.gradle.org/distributions/gradle-6.1-bin.zip ............................................................................................ Welcome to Gradle 6.1! Here are the highlights of this release: - Dependency cache is relocatable - Configurable compilation order between Groovy, Java & Scala - New sample projects in Gradle's documentation For more details see https://docs.gradle.org/6.1/release-notes.html Starting a Gradle Daemon (subsequent builds will be faster) > Task :run 09:04:18.745 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1098ms. Server Running: http://localhost:8080 <=========----> 75% EXECUTING [1m 9s] > IDLE > IDLE > IDLE > :run
色々とライブラリがインストールされているのを眺めていたら終わったのでhttp://localhost:8080/ にアクセス https://gyazo.com/acda7787293e720c6e03049318038a7f
JSON形式で表示された
HelloWorldしてみる https://gyazo.com/0c1425d33e86c64e18b6bcf4c17c4299
$ curl http://localhost:8080/hello Hello World
プロジェクトの構造
- Dockerfileがデフォルトで作成されている。
- GraalVM上で動かすことが前提になっているから?
tree . ├── Dockerfile ├── build │ ├── classes │ │ └── java │ │ └── main │ │ ├── META-INF │ │ │ └── services │ │ │ └── io.micronaut.inject.BeanDefinitionReference │ │ └── hello │ │ └── world │ │ ├── $HelloWorldControllerDefinition$$exec1.class │ │ ├── $HelloWorldControllerDefinition.class │ │ ├── $HelloWorldControllerDefinitionClass.class │ │ ├── Application.class │ │ └── HelloWorldController.class │ ├── generated │ │ └── sources │ │ └── annotationProcessor │ │ └── java │ │ └── main │ ├── resources │ │ └── main │ │ ├── application.yml │ │ └── logback.xml │ └── tmp │ └── compileJava ├── build.gradle ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── micronaut-cli.yml ├── settings.gradle └── src ├── main │ ├── java │ │ └── hello │ │ └── world │ │ ├── Application.java │ │ └── HelloWorldController.java │ └── resources │ ├── application.yml │ └── logback.xml └── test └── java └── hello └── world