9.1.1 FunctionApplication

This section applies to Java & Kotlin functions - for functions written in Groovy, see Groovy Functions.

In order to enable Micronaut’s DI features in a deployed function, your project’s main class must be set to the FunctionApplication class. Typically this will be done in your build.gradle or pom.xml files, as seen in the examples below:

Example build.gradle

  1. mainClassName = "io.micronaut.function.executor.FunctionApplication"

Example pom.xml

  1. <project>
  2. <properties>
  3. <exec.mainClass>io.micronaut.function.executor.FunctionApplication</exec.mainClass>
  4. </properties>
  5. </project>

The FunctionApplication will lookup the function to execute from the property micronaut.function.name.

By default micronaut.function.name is configured in application.yml and set to a single function. You can however control which function to execute by setting the environment variable equivalent MICRONAUT_FUNCTION_NAME.

This approach allows you to package multiple functions into a single application unit (JAR file) and control which function is executed by passing either -Dmicronaut.function.name=myfunction or setting the environment variable.