Skip to content

Commit 27694da

Browse files
committed
clarify azure main-class and boot plugin configuraitons
1 parent fd9b6d5 commit 27694da

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

docs/src/main/asciidoc/adapters/azure-intro.adoc

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ TIP: Use the Java annotations included in the https://learn.microsoft.com/en-us/
9898

9999
The implementation of the business logic used inside the Azure handlers looks like a common Spring application:
100100

101+
[[HttpTriggerDemoApplication]]
102+
101103
[source,java]
102104
----
103105
@SpringBootApplication // <1>
@@ -130,7 +132,7 @@ For that purpose the `AzureFunctionUtil.enhanceInputIfNecessary` allow you to ad
130132

131133
[source,java]
132134
----
133-
@FunctionName("myazurefunction")
135+
@FunctionName("myfunction")
134136
public String execute(
135137
@HttpTrigger(name = "req", authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
136138
ExecutionContext context) {
@@ -163,7 +165,7 @@ public Function<Message<String>, String> uppercase(JsonMapper mapper) {
163165

164166
In order to run Spring Cloud Function applications on Microsoft Azure, you have to use the Maven or Gradle plugins offered by Azure.
165167
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.
166-
The <<disable-spring-boot-layout,Disable Spring Boot Layout>> section below explains how to handle this.
168+
The <<disable-spring-boot-plugin,Disable Spring Boot Plugin>> section below explains how to handle this.
167169
You have to provide Azure specific configurations such as the `resourceGroup`, `appName` and other optional properties.
168170
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].
169171

@@ -249,17 +251,33 @@ azurefunctions {
249251
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.
250252

251253

252-
==== Disable Spring Boot Layout
254+
==== Disable Spring Boot Plugin
253255

254-
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.
255-
Therefore we can't use the (standard) Spring Boot packaging.
256-
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.
257-
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.
256+
Expectedly, the Azure Functions run inside the Azure execution runtime, not inside the SpringBoot runtime!
257+
Furthermore, Azure expects a specific packaging format, generated by the Azure Maven/Gradle plugins, that is not compatible with the default Spring Boot packaging.
258258

259-
==== Provide Main-Class
259+
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:
260+
261+
[source,xml]
262+
----
263+
<plugin>
264+
<groupId>org.springframework.boot</groupId>
265+
<artifactId>spring-boot-maven-plugin</artifactId>
266+
<dependencies>
267+
<dependency>
268+
<groupId>org.springframework.boot.experimental</groupId>
269+
<artifactId>spring-boot-thin-layout</artifactId>
270+
</dependency>
271+
</dependencies>
272+
</plugin>
273+
----
260274

261275
[[star-class-configuration]]
262-
Next you must specify the `Start-Class` or `Main-Class` to point to your application main class.
276+
==== Main-Class Configuration
277+
278+
Specify the `Main-Class`/`Start-Class` to point to your Spring application entry point, such as the <<HttpTriggerDemoApplication,HttpTriggerDemoApplication>> class in the example above.
279+
280+
You can use the Maven `start-class` property or set the `Main-Class` attribute of your `MANIFEST/META-INFO`:
263281

264282
====
265283
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
@@ -284,23 +302,11 @@ jar {
284302
----
285303
====
286304

287-
Alternatively you can explicitly set the main class using the `MAIN_CLASS` environment variable.
288-
289-
For local runs, you can set the `MAIN_CLASS` in your the `local.settings.json`:
305+
TIP: Alternatively you can use the `MAIN_CLASS` environment variable to set the class name explicitly.
306+
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].
290307

291-
[source,json]
292-
----
293-
{
294-
"IsEncrypted": false,
295-
"Values": {
296-
... ,
297-
"MAIN_CLASS": "YOUR-APP-MAIN-CLASS"
298-
}
299-
}
300-
----
301308

302-
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.
303-
The first main class annotated with a `@SpringBootApplication` or `@SpringBootConfiguration` is selected.
309+
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.
304310

305311
==== Configuration Metadata
306312

0 commit comments

Comments
 (0)