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
mainClassName = "io.micronaut.function.executor.FunctionApplication"
Example pom.xml
<project>
<properties>
<exec.mainClass>io.micronaut.function.executor.FunctionApplication</exec.mainClass>
</properties>
</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.