6

I am very new to Micronaut and I just want to ask because I couldnt get any answers from the offical docs

I have a .env file on the root of my folder. Here's my .env

PORT=8081

I tried to access the PORT variable on my application.yml but it is not reading the variable from .env file. Here's my application.yml

micronaut:
    application:
        name: test-app
    server:
        port:${PORT}

1 Answers1

3

You need to tell to micronaut to use .env file if you want to use it.
Generally micronaut uses application.yml so you can configure your app with the following way:

Micronaut reads environment variables from the OS. Our application.yml would look like this:

micronaut:
    application:
        name: test-app
    server:
        port:${PORT:8000} # :8000 is a default value.

Now for example on linux start without env variable:

$ ./mvnw mn:run # start micronaut 
[main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 1102ms. Server Running: http://localhost:8000

Start with env variable:

$ export PORT=8080
$ ./mvnw mn:run # start micronaut 
[main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 1102ms. Server Running: http://localhost:8080

As you can see it will took the variable from your OS path.

jics
  • 1,897
  • 3
  • 15
  • 24