-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for Spring Cloud Azure to 5.15 (#752)
* update Spring Cloud Azure 5.15 update Spring Boot 3.3.2/Spring Cloud 2023.0.3 set 5.x as default version * fix Build with maven * fix CodeQL * support spring3 * fix duplicate name
- Loading branch information
Showing
136 changed files
with
3,532 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ spring: | |
config: | ||
message: Hi | ||
feature-management: | ||
beta: true | ||
Beta: true | ||
dark-theme: | ||
enabled-for: | ||
- | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ava/com/example/demo/DemoApplication.java → ...ava/com/example/demo/DemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
.../demo/configuration/AppConfiguration.java → .../demo/configuration/AppConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ple/demo/controllers/HelloController.java → ...ple/demo/controllers/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ample/demo/impl/TargetingContextImpl.java → ...ample/demo/impl/TargetingContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
79 changes: 79 additions & 0 deletions
79
...t-web/spring3samples/spring-cloud-azure-feature-management-web-sample/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
page_type: sample | ||
languages: | ||
- java | ||
products: | ||
- azure-app-configuration | ||
name: Managing Features and Get Configurations From App Configuration in Spring Boot Web Application | ||
description: This sample demonstrates how to manage features and how to get configurations from App Configuration to Spring Environment in Spring Boot web application. | ||
--- | ||
|
||
# Managing Features and Get Configurations From App Configuration in Spring Boot Web Application | ||
|
||
This sample describes how to use [spring-cloud-azure-feature-management](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/spring/spring-cloud-azure-feature-management/README.md) to manage features and how to get configurations from App Configuration Service to Spring Environment. | ||
|
||
## Key concepts | ||
## Getting started | ||
|
||
|
||
|
||
### How to run without App Configuration Service | ||
Start the application and access http://localhost:8080 to check the resulting console output. | ||
|
||
1. Load features from application.yml | ||
``` | ||
mvn spring-boot:run | ||
``` | ||
|
||
2. Check the returned value, you will see the following information displayed: **Run the Beta filter**. | ||
|
||
### How to run with App Configuration Service | ||
|
||
#### Prepare data | ||
|
||
1. Create a Configuration Store if not exist. | ||
|
||
2. Import the data file src/main/resources/data/sample-data.yml into the Configuration Store created above. Under `For language` select `Other`. Under `File type` select `Yaml`. | ||
|
||
#### Configure the bootstrap.yaml | ||
|
||
Change the connection-string value with the Access Key value of the Configuration Store created above. | ||
|
||
#### Run the application | ||
Start the application and access http://localhost:8080 to check the returned value. Different commands for different scenarios are listed below. | ||
|
||
1. Load properties similar with from application.properties, i.e., keys starting with /application/ | ||
``` | ||
mvn spring-boot:run | ||
``` | ||
|
||
2. Load properties similar with from application_dev.properties, i.e., keys starting with /application_dev | ||
``` | ||
mvn -Dspring.profiles.active=dev spring-boot:run | ||
``` | ||
|
||
3. Load properties similar with from foo.properties, i.e., keys starting with /foo/ | ||
``` | ||
mvn -Dspring.application.name=foo spring-boot:run | ||
``` | ||
|
||
4. Load properties similar with from foo_dev.properties, i.e., keys starting with /foo_dev/ | ||
``` | ||
mvn -Dspring.application.name=foo -Dspring.profiles.active=dev spring-boot:run | ||
``` | ||
|
||
### More details | ||
|
||
Please refer to this [README](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/spring/spring-cloud-azure-starter-appconfiguration-config/README.md) about more usage details. | ||
|
||
## Deploy to Azure Spring Apps | ||
|
||
Now that you have the Spring Boot application running locally, it's time to move it to production. [Azure Spring Apps](https://learn.microsoft.com/azure/spring-apps/overview) makes it easy to deploy Spring Boot applications to Azure without any code changes. The service manages the infrastructure of Spring applications so developers can focus on their code. Azure Spring Apps provides lifecycle management using comprehensive monitoring and diagnostics, configuration management, service discovery, CI/CD integration, blue-green deployments, and more. To deploy your application to Azure Spring Apps, see [Deploy your first application to Azure Spring Apps](https://learn.microsoft.com/azure/spring-apps/quickstart?tabs=Azure-CLI). | ||
|
||
## Examples | ||
## Troubleshooting | ||
## Next steps | ||
## Contributing | ||
|
||
<!-- LINKS --> | ||
|
46 changes: 46 additions & 0 deletions
46
...re-management-web/spring3samples/spring-cloud-azure-feature-management-web-sample/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.azure.spring</groupId> | ||
<artifactId>azure-spring-boot-samples</artifactId> | ||
<version>1.0.0</version> | ||
<relativePath>../../../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>spring-cloud-azure-feature-management-web-sample</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Manage Features and Get Configurations From App Configuration For Web Service</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.azure.spring</groupId> | ||
<artifactId>spring-cloud-azure-feature-management-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-logging</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.annotation</groupId> | ||
<artifactId>jakarta.annotation-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...ng-cloud-azure-feature-management-web-sample/src/main/java/com/example/FeatureFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.example; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
|
||
import com.azure.spring.cloud.feature.management.FeatureManager; | ||
import jakarta.servlet.Filter; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FeatureFilter implements Filter { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FeatureFilter.class); | ||
|
||
@Autowired | ||
private FeatureManager featureManager; | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
if (!featureManager.isEnabledAsync("Beta").block()) { | ||
chain.doFilter(request, response); | ||
return; | ||
} | ||
LOGGER.info("Run the Beta filter"); | ||
chain.doFilter(request, response); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...feature-management-web-sample/src/main/java/com/example/FeatureManagerWebApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.example; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class FeatureManagerWebApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(FeatureManagerWebApplication.class, args); | ||
} | ||
|
||
} | ||
|
53 changes: 53 additions & 0 deletions
53
...-cloud-azure-feature-management-web-sample/src/main/java/com/example/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.example; | ||
|
||
import com.azure.spring.cloud.feature.management.FeatureManager; | ||
import com.azure.spring.cloud.feature.management.web.FeatureGate; | ||
import com.azure.spring.cloud.feature.management.web.FeatureManagerSnapshot; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
|
||
@Controller | ||
@ConfigurationProperties("controller") | ||
public class HelloController { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(HelloController.class); | ||
|
||
@Autowired | ||
private FeatureManager featureManager; | ||
|
||
@Autowired | ||
private FeatureManagerSnapshot featureManagerSnapshot; | ||
|
||
@GetMapping("/privacy") | ||
public String getRequestBased(Model model) { | ||
model.addAttribute("Beta", featureManager.isEnabledAsync("beta").block()); | ||
model.addAttribute("isDarkThemeS1", featureManagerSnapshot.isEnabledAsync("dark-theme").block()); | ||
model.addAttribute("isDarkThemeS2", featureManagerSnapshot.isEnabledAsync("dark-theme").block()); | ||
model.addAttribute("isDarkThemeS3", featureManagerSnapshot.isEnabledAsync("dark-theme").block()); | ||
return "privacy"; | ||
} | ||
|
||
@GetMapping(value = {"/Beta", "/BetaA"}) | ||
@FeatureGate(feature = "beta-ab", fallback = "/BetaB") | ||
public String getRedirect(Model model) { | ||
return "BetaA"; | ||
} | ||
|
||
@GetMapping("/BetaB") | ||
public String getRedirected(Model model) { | ||
return "BetaB"; | ||
} | ||
|
||
@GetMapping(value = {"", "/", "/welcome"}) | ||
public String mainWithParam(Model model) { | ||
model.addAttribute("Beta", featureManager.isEnabledAsync("beta").block()); | ||
return "welcome"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...loud-azure-feature-management-web-sample/src/main/java/com/example/MessageProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.example; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "config") | ||
public class MessageProperties { | ||
private String message; | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
Oops, something went wrong.