From 27694da4816099a8215e029e4e3bb43b6b7d8021 Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Fri, 21 Jul 2023 19:53:13 +0200 Subject: [PATCH] clarify azure main-class and boot plugin configuraitons --- .../main/asciidoc/adapters/azure-intro.adoc | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/docs/src/main/asciidoc/adapters/azure-intro.adoc b/docs/src/main/asciidoc/adapters/azure-intro.adoc index 2c74f5717..fea4a73f3 100644 --- a/docs/src/main/asciidoc/adapters/azure-intro.adoc +++ b/docs/src/main/asciidoc/adapters/azure-intro.adoc @@ -98,6 +98,8 @@ TIP: Use the Java annotations included in the https://learn.microsoft.com/en-us/ The implementation of the business logic used inside the Azure handlers looks like a common Spring application: +[[HttpTriggerDemoApplication]] + [source,java] ---- @SpringBootApplication // <1> @@ -130,7 +132,7 @@ For that purpose the `AzureFunctionUtil.enhanceInputIfNecessary` allow you to ad [source,java] ---- -@FunctionName("myazurefunction") +@FunctionName("myfunction") public String execute( @HttpTrigger(name = "req", authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, ExecutionContext context) { @@ -163,7 +165,7 @@ public Function, String> uppercase(JsonMapper mapper) { In order to run Spring Cloud Function applications on Microsoft Azure, you have to use the Maven or Gradle plugins offered by Azure. Later imposes a specific https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#folder-structure[package archive structure] that interferes with the `standard` Spring Boot package jars. -The <> section below explains how to handle this. +The <> section below explains how to handle this. You have to provide Azure specific configurations such as the `resourceGroup`, `appName` and other optional properties. More information about the runtime configurations: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#java-versions[Java Versions], https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#specify-the-deployment-os[Deployment OS]. @@ -249,17 +251,33 @@ azurefunctions { The complete plugin documentation is available at the https://github.com/microsoft/azure-maven-plugins/tree/develop/azure-functions-maven-plugin[Azure Maven] and https://github.com/microsoft/azure-gradle-plugins/tree/master/azure-functions-gradle-plugin[Azure Gradle] repositories. -==== Disable Spring Boot Layout +==== Disable Spring Boot Plugin -The Azure Functions come with their own (non-Boot) execution runtime that imposes its own packaging format generated by the Azure's maven/gradle plugins. -Therefore we can't use the (standard) Spring Boot packaging. -You have to either disable the Spring-Boot plugin all together or opt for the https://github.com/dsyer/spring-boot-thin-launcher[spring-boot-thin-launcher] instead. -This https://github.com/spring-cloud/spring-cloud-function/blob/3bafcc59175fb61e323e393487d413441287a450/spring-cloud-function-samples/function-sample-azure-http-trigger/pom.xml#L97-L107[snipped] illustrates how to use the `spring-boot-thin-launcher` for Maven. +Expectedly, the Azure Functions run inside the Azure execution runtime, not inside the SpringBoot runtime! +Furthermore, Azure expects a specific packaging format, generated by the Azure Maven/Gradle plugins, that is not compatible with the default Spring Boot packaging. -==== Provide Main-Class +IMPORTANT: You have to either disable the SpringBoot Maven/Gradle plugin or use the https://github.com/dsyer/spring-boot-thin-launcher[Spring Boot Thin Launcher] as shown in this Maven snipped: + +[source,xml] +---- + + org.springframework.boot + spring-boot-maven-plugin + + + org.springframework.boot.experimental + spring-boot-thin-layout + + + +---- [[star-class-configuration]] -Next you must specify the `Start-Class` or `Main-Class` to point to your application main class. +==== Main-Class Configuration + +Specify the `Main-Class`/`Start-Class` to point to your Spring application entry point, such as the <> class in the example above. + +You can use the Maven `start-class` property or set the `Main-Class` attribute of your `MANIFEST/META-INFO`: ==== [source,xml,indent=0,subs="verbatim,attributes",role="primary"] @@ -284,23 +302,11 @@ jar { ---- ==== -Alternatively you can explicitly set the main class using the `MAIN_CLASS` environment variable. +TIP: Alternatively you can use the `MAIN_CLASS` environment variable to set the class name explicitly. +For local runs, add the `MAIN_CLASS` variable to your `local.settings.json` file and for Azure portal deployment set the variable in the https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#get-started-in-the-azure-portal[App Settings]. -For local runs, you can set the `MAIN_CLASS` in your the `local.settings.json`: -[source,json] ----- -{ - "IsEncrypted": false, - "Values": { - ... , - "MAIN_CLASS": "YOUR-APP-MAIN-CLASS" - } -} ----- - -IMPORTANT: When not set via the `MAIN_CLASS` variable, the Azure adapter will try to retrieve the main class from the `MANIFEST/META-INFO` sections of all dependencies. -The first main class annotated with a `@SpringBootApplication` or `@SpringBootConfiguration` is selected. +IMPORTANT: If the `MAIN_CLASS` variable is not set, the Azure adapter lookups the `MANIFEST/META-INFO` attributes from the jars found on the classpath and selects the first `Main-Class:` annotated with either a `@SpringBootApplication` or `@SpringBootConfiguration` annotation. ==== Configuration Metadata