Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot Cloud Config #1230

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
37726c0
style(springboot autoconfigure): use a PROPERTY_PREFIX instead of har…
lony2003 Mar 4, 2025
8e8b5fb
feat(springboot cloudconfig): A new library that implement a backend …
lony2003 Mar 4, 2025
3b55b4c
style(springboot cloudconfig): update file header
lony2003 Mar 5, 2025
c318d8b
style(springboot cloudconfig): change code style to match checkstyle
lony2003 Mar 5, 2025
3fb8cab
feat(springboot cloudconfig): Implement Configuration Cloud Config Im…
lony2003 Mar 6, 2025
6724b46
fix(springboot cloudconfig): Update version of dapr-spring-parent
lony2003 Mar 6, 2025
49c1ab6
feat(springboot cloudconfig): test cases for cloud config
lony2003 Mar 7, 2025
b6de0b8
fix(springboot cloudconfig): Fix problems of PropertySourceLoader
lony2003 Mar 7, 2025
3359473
feat(springboot cloudconfig): Change the behavior of Config Type
lony2003 Mar 8, 2025
b7e660e
test(springboot cloudconfig): Implemented integration test for secret…
lony2003 Mar 8, 2025
653bb12
test(springboot cloudconfig): fix integration test for secret and con…
lony2003 Mar 8, 2025
1169c54
docs(springboot cloudconfig): Write examples and docs for springboot …
lony2003 Mar 8, 2025
f5fab34
style(springboot cloudconfig): Clean comments
lony2003 Mar 10, 2025
852d459
docs(springboot cloudconfig): Fix typo of import
lony2003 Mar 10, 2025
29fa755
test(springboot cloudconfig): Fix test coverage
lony2003 Mar 27, 2025
74e36d4
docs(cloud-config-demo): enhence Kubernetes cluster usages
lony2003 Mar 29, 2025
716ecb7
docs(cloud-config-demo): enhence Kubernetes cluster usages
lony2003 Mar 30, 2025
ffc43d3
docs(cloud-config-demo): enhence Kubernetes cluster usages
lony2003 Mar 30, 2025
186b1bb
docs(springboot cloudconfig): A fix of example docs.
lony2003 Apr 2, 2025
15fefb1
Update springboot to latest minor.patch version. (#826)
artursouza Feb 2, 2023
a31ce67
docs(springboot cloudconfig): A fix of example docs.
lony2003 Apr 2, 2025
70d4eea
docs(springboot cloudconfig): A fix of example docs.
lony2003 Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import io.dapr.spring.data.DaprKeyValueAdapterResolver;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "dapr.client")
@ConfigurationProperties(prefix = DaprClientProperties.PROPERTY_PREFIX)
public class DaprClientProperties {
public static final String PROPERTY_PREFIX = "dapr.client";

private String httpEndpoint;
private String grpcEndpoint;
private Integer httpPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>dapr-spring-workflows</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-cloudconfig</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
79 changes: 79 additions & 0 deletions dapr-spring/dapr-spring-cloudconfig/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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>io.dapr.spring</groupId>
<artifactId>dapr-spring-parent</artifactId>
<version>0.15.0-SNAPSHOT</version>
</parent>

<artifactId>dapr-spring-cloudconfig</artifactId>
<name>dapr-spring-cloudconfig</name>
<description>Dapr Spring Cloud Config</description>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-data</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-messaging</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dapr.spring</groupId>
<artifactId>dapr-spring-workflows</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.2.0</version>
<configuration>
<excludeFilterFile>./spotbugs-exclude.xml</excludeFilterFile>
<failOnError>${spotbugs.fail}</failOnError>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
21 changes: 21 additions & 0 deletions dapr-spring/dapr-spring-cloudconfig/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<FindBugsFilter>
<Match>
<Package name="~io\.dapr\.spring.*"/>
<Bug pattern="EI_EXPOSE_REP"/>
</Match>

<Match>
<Package name="~io\.dapr\.spring.*"/>
<Bug pattern="EI_EXPOSE_REP2"/>
</Match>
<Match>
<Class name="~io.dapr.spring.boot.cloudconfig.configdata.*"/>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>
<Match>
<Class name="~io.dapr.spring.boot.cloudconfig.*"/>
<Bug pattern="MS_EXPOSE_REP"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2025 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.spring.boot.cloudconfig.autoconfigure;

import io.dapr.client.DaprClient;
import io.dapr.spring.boot.cloudconfig.config.DaprCloudConfigProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(DaprCloudConfigProperties.class)
@ConditionalOnProperty(name = DaprCloudConfigProperties.PROPERTY_PREFIX + ".enabled", matchIfMissing = true)
@ConditionalOnClass(DaprClient.class)
public class DaprCloudConfigAutoConfiguration {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2025 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.spring.boot.cloudconfig.config;

import io.dapr.spring.boot.autoconfigure.client.DaprClientProperties;
import io.dapr.spring.boot.autoconfigure.client.DaprConnectionDetails;

class CloudConfigPropertiesDaprConnectionDetails implements DaprConnectionDetails {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lony2003 do we need to duplicate the DaprConnectionDetails, why are these different for the normal DaprConnectionDetails?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No difference, just because the PropertyDaprConnectionDetails is protected and can't be used in another package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artur-ciocanu should we change the PropertyDaprConnectionDetails visibility so it can be reused?


private final DaprClientProperties daprClientProperties;

public CloudConfigPropertiesDaprConnectionDetails(DaprClientProperties daprClientProperties) {
this.daprClientProperties = daprClientProperties;
}

@Override
public String httpEndpoint() {
return this.daprClientProperties.getHttpEndpoint();
}

@Override
public String grpcEndpoint() {
return this.daprClientProperties.getGrpcEndpoint();
}

@Override
public Integer httpPort() {
return this.daprClientProperties.getHttpPort();
}

@Override
public Integer grpcPort() {
return this.daprClientProperties.getGrpcPort();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2025 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.spring.boot.cloudconfig.config;

import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
import io.dapr.client.DaprPreviewClient;
import io.dapr.config.Properties;
import io.dapr.spring.boot.autoconfigure.client.DaprClientProperties;
import io.dapr.spring.boot.autoconfigure.client.DaprConnectionDetails;

public class DaprCloudConfigClientManager {

private static DaprClient daprClient;
private static DaprPreviewClient daprPreviewClient;
private final DaprCloudConfigProperties daprCloudConfigProperties;
private final DaprClientProperties daprClientConfig;

/**
* Create a DaprCloudConfigClientManager to create Config-Specific Dapr Client.
*
* @param daprCloudConfigProperties Properties of Dapr Cloud Config
* @param daprClientConfig Properties of Dapr Client
*/
public DaprCloudConfigClientManager(DaprCloudConfigProperties daprCloudConfigProperties,
DaprClientProperties daprClientConfig) {
this.daprCloudConfigProperties = daprCloudConfigProperties;
this.daprClientConfig = daprClientConfig;

DaprClientBuilder daprClientBuilder = createDaprClientBuilder(
createDaprConnectionDetails(daprClientConfig)
);

if (DaprCloudConfigClientManager.daprClient == null) {
DaprCloudConfigClientManager.daprClient = daprClientBuilder.build();

Check warning on line 46 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L46

Added line #L46 was not covered by tests
}

if (DaprCloudConfigClientManager.daprPreviewClient == null) {
DaprCloudConfigClientManager.daprPreviewClient = daprClientBuilder.buildPreviewClient();
}
}

public static DaprPreviewClient getDaprPreviewClient() {
return DaprCloudConfigClientManager.daprPreviewClient;

Check warning on line 55 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L55

Added line #L55 was not covered by tests
}

public static DaprClient getDaprClient() {
return DaprCloudConfigClientManager.daprClient;
}

private DaprConnectionDetails createDaprConnectionDetails(DaprClientProperties properties) {
return new CloudConfigPropertiesDaprConnectionDetails(properties);
}

DaprClientBuilder createDaprClientBuilder(DaprConnectionDetails daprConnectionDetails) {
DaprClientBuilder builder = new DaprClientBuilder();
if (daprConnectionDetails.httpEndpoint() != null) {
builder.withPropertyOverride(Properties.HTTP_ENDPOINT, daprConnectionDetails.httpEndpoint());

Check warning on line 69 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L69

Added line #L69 was not covered by tests
}
if (daprConnectionDetails.grpcEndpoint() != null) {
builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint());

Check warning on line 72 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L72

Added line #L72 was not covered by tests
}
if (daprConnectionDetails.httpPort() != null) {
builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort()));

Check warning on line 75 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L75

Added line #L75 was not covered by tests
}
if (daprConnectionDetails.grpcPort() != null) {
builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort()));

Check warning on line 78 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L78

Added line #L78 was not covered by tests
}
return builder;
}

public DaprCloudConfigProperties getDaprCloudConfigProperties() {
return daprCloudConfigProperties;
}

public DaprClientProperties getDaprClientConfig() {
return daprClientConfig;

Check warning on line 88 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigClientManager.java#L88

Added line #L88 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2025 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.spring.boot.cloudconfig.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* The properties for creating dapr client.
*/
@ConfigurationProperties(DaprCloudConfigProperties.PROPERTY_PREFIX)
public class DaprCloudConfigProperties {

public static final String PROPERTY_PREFIX = "dapr.cloudconfig";

/**
* whether enable cloud config.
*/
private Boolean enabled = true;

/**
* whether enable dapr client wait for sidecar, if no response, will throw IOException.
*/
private Boolean waitSidecarEnabled = false;

/**
* retries of dapr client wait for sidecar.
*/
private Integer waitSidecarRetries = 3;

/**
* get config timeout (include wait for dapr sidecar).
*/
private Integer timeout = 2000;

public Integer getTimeout() {
return timeout;
}

public void setTimeout(Integer timeout) {
this.timeout = timeout;
}

Check warning on line 52 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigProperties.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigProperties.java#L51-L52

Added lines #L51 - L52 were not covered by tests

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public Boolean getWaitSidecarEnabled() {
return waitSidecarEnabled;
}

public void setWaitSidecarEnabled(Boolean waitSidecarEnabled) {
this.waitSidecarEnabled = waitSidecarEnabled;
}

public Integer getWaitSidecarRetries() {
return waitSidecarRetries;
}

public void setWaitSidecarRetries(Integer waitSidecarRetries) {
this.waitSidecarRetries = waitSidecarRetries;
}

Check warning on line 76 in dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigProperties.java

View check run for this annotation

Codecov / codecov/patch

dapr-spring/dapr-spring-cloudconfig/src/main/java/io/dapr/spring/boot/cloudconfig/config/DaprCloudConfigProperties.java#L75-L76

Added lines #L75 - L76 were not covered by tests
}
Loading
Loading