Skip to content

Commit d5ff549

Browse files
Copiloteggboy
andauthored
Add Azure Functions support with spring-cloud-function-adapter-azure-web
- Replace spring-cloud-function-context with spring-cloud-function-adapter-azure-web 5.0.1 - Add azure-functions-maven-plugin 1.41.0 for building and running Azure Functions - Add spring-boot-thin-layout for thin JAR packaging - Set start-class property for Azure Function runtime entry point - Create host.json for Azure Functions runtime configuration - Create local.settings.json for local development - Update .gitignore with Azure Functions artifacts - Update README with build/run/deploy instructions Agent-Logs-Url: https://github.com/eggboy/springcloud-azurefunction/sessions/1bca7a50-e3eb-449d-a47f-1fef2633218f Co-authored-by: eggboy <825593+eggboy@users.noreply.github.com>
1 parent b71255e commit d5ff549

4 files changed

Lines changed: 101 additions & 2 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ build/
3131

3232
### VS Code ###
3333
.vscode/
34+
35+
### Azure Functions ###
36+
local.settings.json
37+
obj/
38+
bin/

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
11
[![CodeQL](https://github.com/eggboy/springcloud-azurefunction/actions/workflows/codeql.yml/badge.svg)](https://github.com/eggboy/springcloud-azurefunction/actions/workflows/codeql.yml)
22
# springcloud-azurefunction
3-
Azure Function built with Spring Cloud Function in Java 17
3+
Azure Function built with Spring Cloud Function in Java 21
4+
5+
## Prerequisites
6+
7+
- JDK 21
8+
- Maven
9+
- [Azure Functions Core Tools](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local) v4+
10+
11+
## Build
12+
13+
```shell
14+
mvn clean package
15+
```
16+
17+
## Run Locally
18+
19+
```shell
20+
mvn azure-functions:run
21+
```
22+
23+
Then use `curl` to interact with the REST API:
24+
25+
```shell
26+
# Create a user
27+
curl -X POST -H 'Content-Type:application/json' http://localhost:7072/api/AzureWebAdapter/user -d '{"userId":"1","lastName":"Doe","firstName":"John","email":"john@example.com"}'
28+
29+
# Get a user
30+
curl -X GET http://localhost:7072/api/AzureWebAdapter/user/1
31+
```
32+
33+
## Deploy to Azure
34+
35+
```shell
36+
az login
37+
mvn azure-functions:deploy
38+
```

pom.xml

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
<properties>
1717
<java.version>21</java.version>
1818
<spring-cloud.version>2025.0.2</spring-cloud.version>
19+
<spring-boot-thin-layout.version>1.0.31.RELEASE</spring-boot-thin-layout.version>
20+
<spring-cloud-function-adapter-azure-web.version>5.0.1</spring-cloud-function-adapter-azure-web.version>
21+
<start-class>io.jaylee.springcloud.AzurefunctionApplication</start-class>
22+
<azure.functions.maven.plugin.version>1.41.0</azure.functions.maven.plugin.version>
23+
<functionAppName>springcloud-azurefunction</functionAppName>
24+
<functionAppRegion>koreacentral</functionAppRegion>
25+
<functionResourceGroup>java-functions-group</functionResourceGroup>
1926
</properties>
2027
<dependencies>
2128
<dependency>
@@ -28,7 +35,8 @@
2835
</dependency>
2936
<dependency>
3037
<groupId>org.springframework.cloud</groupId>
31-
<artifactId>spring-cloud-function-context</artifactId>
38+
<artifactId>spring-cloud-function-adapter-azure-web</artifactId>
39+
<version>${spring-cloud-function-adapter-azure-web.version}</version>
3240
</dependency>
3341

3442
<dependency>
@@ -61,6 +69,43 @@
6169

6270
<build>
6371
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-deploy-plugin</artifactId>
75+
<configuration>
76+
<skip>true</skip>
77+
</configuration>
78+
</plugin>
79+
<plugin>
80+
<groupId>com.microsoft.azure</groupId>
81+
<artifactId>azure-functions-maven-plugin</artifactId>
82+
<version>${azure.functions.maven.plugin.version}</version>
83+
<configuration>
84+
<appName>${functionAppName}</appName>
85+
<resourceGroup>${functionResourceGroup}</resourceGroup>
86+
<region>${functionAppRegion}</region>
87+
<hostJson>${project.basedir}/src/main/resources/host.json</hostJson>
88+
<runtime>
89+
<os>linux</os>
90+
<javaVersion>21</javaVersion>
91+
</runtime>
92+
<funcPort>7072</funcPort>
93+
<appSettings>
94+
<property>
95+
<name>FUNCTIONS_EXTENSION_VERSION</name>
96+
<value>~4</value>
97+
</property>
98+
</appSettings>
99+
</configuration>
100+
<executions>
101+
<execution>
102+
<id>package-functions</id>
103+
<goals>
104+
<goal>package</goal>
105+
</goals>
106+
</execution>
107+
</executions>
108+
</plugin>
64109
<plugin>
65110
<groupId>org.springframework.boot</groupId>
66111
<artifactId>spring-boot-maven-plugin</artifactId>
@@ -72,6 +117,13 @@
72117
</exclude>
73118
</excludes>
74119
</configuration>
120+
<dependencies>
121+
<dependency>
122+
<groupId>org.springframework.boot.experimental</groupId>
123+
<artifactId>spring-boot-thin-layout</artifactId>
124+
<version>${spring-boot-thin-layout.version}</version>
125+
</dependency>
126+
</dependencies>
75127
</plugin>
76128
</plugins>
77129
</build>

src/main/resources/host.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "2.0",
3+
"extensionBundle": {
4+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5+
"version": "[4.*, 5.0.0)"
6+
}
7+
}

0 commit comments

Comments
 (0)