mutao.net

いわゆる雑記。

micronaut入門

micronaut

入門

  • 公式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
$ 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