Using the CLI you can create a new Micronaut application in either Groovy, Java or Kotlin (the default is Java).
The following command creates a new “Hello World” server application in Java with a Gradle build:
$ ./gradlew run
> Task :run
[main] INFO io.micronaut.runtime.Micronaut - Startup completed in 972ms. Server Running: http://localhost:28933
If you have created a Maven based project, use ./mvnw mn:run
instead.
By default the Micronaut HTTP server is configured to run on port 8080. See the section in the user guide for more options.
import io.micronaut.http.MediaType
@Controller('/hello') (1)
class HelloController {
@Get(produces = MediaType.TEXT_PLAIN) (2)
'Hello World' (3)
}
If you are using Java, place the previous file in src/main/java/hello/world
.
If you are using Groovy, place the previous file in src/main/groovy/hello/world
.
If you are using Kotlin, place the previous file in src/main/kotlin/hello/world
.
If you start the application and send a request to the /hello
URI then the text “Hello World” is returned:
$ curl http://localhost:8080/hello
Hello World