You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -50,8 +50,8 @@ NOTE: version `4.0.0+` is required. Having the adapter on the classpath activate
50
50
51
51
=== Function Implementation
52
52
53
-
You can use the `@Component` (or `@Service`) annotation to turn any exiting Azure Function class (e.g. class with `@FunctionName` annotated handlers) into a Spring component.
54
-
Then you can auto-wire the required dependencies (or the https://docs.spring.io/spring-cloud-function/docs/current/reference/html/spring-cloud-function.html#_function_catalog_and_flexible_function_signatures[FunctionCatalog] instance for Spring Cloud Function) and use those inside your Azure function handler.
53
+
Use the `@Component` (or `@Service`) annotation to turn any exiting Azure Function class (e.g. with `@FunctionName` handlers) into a Spring component.
54
+
Then you can auto-wire the required dependencies (or the https://docs.spring.io/spring-cloud-function/docs/current/reference/html/spring-cloud-function.html#_function_catalog_and_flexible_function_signatures[FunctionCatalog] for Spring Cloud Function composition) and use those inside the Azure function handlers.
55
55
56
56
[source,java]
57
57
----
@@ -64,39 +64,39 @@ public class MyAzureFunction {
64
64
// The FunctionCatalog leverages the Spring Cloud Function framework.
Azure's programming-model uses the https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#java-function-basics[@FunctionName] method annotation to identify the designated function handlers.
88
-
When invoked by a trigger (such as `@HttpTrigger`), functions process that trigger, and any other inputs, to produce one or more outputs.
89
-
90
-
TIP: Use the Java annotations included in the https://learn.microsoft.com/en-us/java/api/com.microsoft.azure.functions.annotation?view=azure-java-stable[com.microsoft.azure.functions.annotation.*] package to bind input and outputs to your methods.
91
87
92
88
<1> Indicates that the `MyAzureFunction` class is a "component" to be considered by the Spring Framework as a candidate for auto-detection and classpath scanning.
93
89
<2> Auto-wire the `uppercase` and `functionCatalog` beans defined in the `HttpTriggerDemoApplication` (below).
94
-
<3> The `plainBean` method handler is mapped to an Azure function that uses of the auto-wired `uppercase` spring bean to compute the result.
90
+
<3> The https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#java-function-basics[@FunctionName] annotation identifies the designated Azure function handlers.
91
+
When invoked by a trigger (such as `@HttpTrigger`), functions process that trigger, and any other inputs, to produce one or more outputs.
92
+
<4> The `plainBean` method handler is mapped to an Azure function that uses of the auto-wired `uppercase` spring bean to compute the result.
95
93
It demonstrates how to use "plain" Spring components in your Azure handlers.
96
-
<4> The `springCloudFunction` method handler is mapped to another Azure function, that uses the auto-wired `FunctionCatalog` instance to compute the result.
97
-
<5> Shows how to leverage the Spring Cloud Function https://docs.spring.io/spring-cloud-function/docs/current/reference/html/spring-cloud-function.html#_function_catalog_and_flexible_function_signatures[FunctionCatalog] composition API.
94
+
<5> The `springCloudFunction` method handler is mapped to another Azure function, that uses the auto-wired `FunctionCatalog` instance to compute the result.
95
+
<6> Shows how to leverage the Spring Cloud Function https://docs.spring.io/spring-cloud-function/docs/current/reference/html/spring-cloud-function.html#_function_catalog_and_flexible_function_signatures[FunctionCatalog] composition API.
98
96
99
-
The actual Spring defined beans used inside the handlers looks like this:
97
+
TIP: Use the Java annotations included in the https://learn.microsoft.com/en-us/java/api/com.microsoft.azure.functions.annotation?view=azure-java-stable[com.microsoft.azure.functions.annotation.*] package to bind input and outputs to your methods.
98
+
99
+
The implementation of the business logic used inside the Azure handlers looks like a common Spring application:
100
100
101
101
[source,java]
102
102
----
@@ -118,7 +118,7 @@ public class HttpTriggerDemoApplication {
118
118
}
119
119
}
120
120
----
121
-
<1> the `@SpringBootApplication` annotated class should be used as Main-Class (or Start-Class) in you Maven/Gradle configurations as explained in <<star-class-configuration, star class configuration>>.
121
+
<1> The `@SpringBootApplication` annotated class is used as a `Main-Class` (or `Start-Class`) as explained in <<star-class-configuration, star class configuration>>.
122
122
<2> Functions auto-wired and used in the Azure function handlers.
123
123
124
124
==== Accessing Azure ExecutionContext
@@ -130,7 +130,7 @@ For that purpose the `AzureFunctionUtil.enhanceInputIfNecessary` allow you to ad
@@ -159,20 +159,16 @@ public Function<Message<String>, String> uppercase(JsonMapper mapper) {
159
159
----
160
160
<1> Retrieve the ExecutionContext instance from the header.
161
161
162
-
=== Configuration and Project Layout
163
-
164
-
You don't need the Spring Cloud Function Web at runtime in Azure, so you can exclude this before you create the JAR you deploy to Azure, but it won't be used if you include it, so it doesn't hurt to leave it in.
165
-
A function application on Azure is an archive generated either by the Maven (`azure-functions-maven-plugin`) or the Gradle(`azure-functions-gradle-plugin`) plugins.
166
-
The function lives in the JAR file generated by this project.
162
+
=== Project Layout
167
163
168
-
The sample creates it as an executable jar, using the thin layout, so that Azure can find the handler classes. If you prefer you can just use a regular flat JAR file.
169
-
The dependencies should *not* be included.
170
-
171
-
In order to run Spring Cloud Function applications on Microsoft Azure, you have to use Maven or Gradle plugins offered by Azure.
172
-
173
-
Provide the Azure-specific configuration for your application, specifying the `resourceGroup`, `appName` and other optional properties.
164
+
In order to run Spring Cloud Function applications on Microsoft Azure, you have to use the Maven or Gradle plugins offered by Azure.
165
+
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.
167
+
You have to provide Azure specific configurations such as the `resourceGroup`, `appName` and other optional properties.
174
168
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].
175
169
170
+
==== Azure Maven/Gradle Plugin
171
+
176
172
Sample Azure Function (Maven/Gradle) configuration would like like:
177
173
178
174
====
@@ -252,6 +248,16 @@ azurefunctions {
252
248
253
249
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.
254
250
251
+
252
+
==== Disable Spring Boot Layout
253
+
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.
258
+
259
+
==== Provide Main-Class
260
+
255
261
[[star-class-configuration]]
256
262
Next you must specify the `Start-Class` or `Main-Class` to point to your application main class.
257
263
@@ -271,31 +277,48 @@ Next you must specify the `Start-Class` or `Main-Class` to point to your applica
271
277
jar {
272
278
manifest {
273
279
attributes(
274
-
"Main-Class": "YOURAPPMAINCLASS"
280
+
"Main-Class": "YOUR-APP-MAIN-CLASS"
275
281
)
276
282
}
277
283
}
278
284
----
279
285
====
280
286
281
-
IMPORTANT: The main class provided must be annotated by `@SpringBootApplication` or `@SpringBootConfiguration` annotation.
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`:
290
+
291
+
[source,json]
292
+
----
293
+
{
294
+
"IsEncrypted": false,
295
+
"Values": {
296
+
... ,
297
+
"MAIN_CLASS": "YOUR-APP-MAIN-CLASS"
298
+
}
299
+
}
300
+
----
282
301
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.
283
304
284
-
You will also have to ensure that the files to be scanned by the plugin can be found in the Azure functions staging directory (see the https://github.com/microsoft/azure-maven-plugins[plugin repository] for more details on the staging directory and it's default location).
305
+
==== Configuration Metadata
285
306
286
-
Add the `host.json` configuration file:
307
+
You can use a shared https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json[host.json] file to configure the function app.
0 commit comments