Skip to content

Commit 82c65c3

Browse files
Siri Varma Vegirajuclaude
authored andcommitted
fix: Add default values to DaprClientProperties for Spring Boot apps
When starting a Spring Boot application without explicitly setting DaprClientProperties, fields are now initialized with Dapr's standard defaults instead of null: httpEndpoint=http://localhost, grpcEndpoint=localhost, httpPort=3500, grpcPort=50001, apiToken=null. Fixes #1566 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Siri Varma Vegiraju <svegiraju@Siris-MacBook-Pro.local>
1 parent f63a4a4 commit 82c65c3

2 files changed

Lines changed: 48 additions & 12 deletions

File tree

dapr-spring/dapr-spring-boot-properties/src/main/java/io/dapr/spring/boot/properties/client/DaprClientProperties.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717

1818
@ConfigurationProperties(prefix = "dapr.client")
1919
public class DaprClientProperties {
20-
private String httpEndpoint;
21-
private String grpcEndpoint;
22-
private Integer httpPort;
23-
private Integer grpcPort;
20+
21+
public static final String DEFAULT_HTTP_ENDPOINT = "http://localhost";
22+
public static final String DEFAULT_GRPC_ENDPOINT = "localhost";
23+
public static final int DEFAULT_HTTP_PORT = 3500;
24+
public static final int DEFAULT_GRPC_PORT = 50001;
25+
26+
private String httpEndpoint = DEFAULT_HTTP_ENDPOINT;
27+
private String grpcEndpoint = DEFAULT_GRPC_ENDPOINT;
28+
private Integer httpPort = DEFAULT_HTTP_PORT;
29+
private Integer grpcPort = DEFAULT_GRPC_PORT;
2430
private String apiToken;
2531

2632
/**

dapr-spring/dapr-spring-boot-properties/src/test/java/io/dapr/spring/boot/properties/client/DaprClientPropertiesTest.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ public class DaprClientPropertiesTest {
2626
private final ApplicationContextRunner runner = new ApplicationContextRunner()
2727
.withUserConfiguration(EnableDaprClientProperties.class);
2828

29+
@Test
30+
@DisplayName("Should have correct default values when using no-arg constructor")
31+
public void shouldHaveCorrectDefaults() {
32+
33+
DaprClientProperties properties = new DaprClientProperties();
34+
35+
SoftAssertions.assertSoftly(softly -> {
36+
softly.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
37+
softly.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
38+
softly.assertThat(properties.getHttpPort()).isEqualTo(3500);
39+
softly.assertThat(properties.getGrpcPort()).isEqualTo(50001);
40+
softly.assertThat(properties.getApiToken()).isNull();
41+
});
42+
}
43+
2944
@Test
3045
@DisplayName("Should create DaprClientProperties correctly through constructor")
3146
public void shouldCreateDaprClientPropertiesCorrectly() {
@@ -49,21 +64,36 @@ public void shouldSetDaprClientPropertiesCorrectly() {
4964

5065
DaprClientProperties properties = new DaprClientProperties();
5166

52-
properties.setGrpcEndpoint("localhost");
53-
properties.setGrpcPort(50001);
54-
properties.setHttpEndpoint("http://localhost");
55-
properties.setHttpPort(3500);
67+
properties.setGrpcEndpoint("custom-host");
68+
properties.setGrpcPort(60001);
69+
properties.setHttpEndpoint("http://custom-host");
70+
properties.setHttpPort(4500);
5671
properties.setApiToken("ABC");
5772

5873
SoftAssertions.assertSoftly(softAssertions -> {
59-
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
60-
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
61-
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
62-
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
74+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("custom-host");
75+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://custom-host");
76+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(4500);
77+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(60001);
6378
softAssertions.assertThat(properties.getApiToken()).isEqualTo("ABC");
6479
});
6580
}
6681

82+
@Test
83+
@DisplayName("Should have correct defaults when no properties are configured")
84+
public void shouldHaveDefaultsWhenNoPropertiesConfigured() {
85+
runner.run(context -> {
86+
DaprClientProperties properties = context.getBean(DaprClientProperties.class);
87+
SoftAssertions.assertSoftly(softly -> {
88+
softly.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
89+
softly.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
90+
softly.assertThat(properties.getHttpPort()).isEqualTo(3500);
91+
softly.assertThat(properties.getGrpcPort()).isEqualTo(50001);
92+
softly.assertThat(properties.getApiToken()).isNull();
93+
});
94+
});
95+
}
96+
6797
@Test
6898
@DisplayName("Should map DaprClient properties correctly")
6999
public void shouldMapDaprClientProperties() {

0 commit comments

Comments
 (0)