Skip to content

Commit 00fae6b

Browse files
committed
fix(springboot openfeign): fix IT failed for tests that have two dapr client bean autowired
Job SDK ITs have a daprPreviewClient bean defined, as SpringBoot bean search will first get beans that impl the interface and get all beans that matches the bean's class, when openfeign autowire DaprClient, there is a conflict between daprClient and daprPreviewClient. Change the AutoConfiguration behavior to make a more strict rule for making AutoConfiguration run Signed-off-by: lony2003 <[email protected]>
1 parent c381e44 commit 00fae6b

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

dapr-spring/dapr-spring-openfeign/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<maven.compiler.source>17</maven.compiler.source>
1919
<maven.compiler.target>17</maven.compiler.target>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<spotbugs.exclude.filter.file>./spotbugs-exclude.xml</spotbugs.exclude.filter.file>
2221
</properties>
2322

2423
<dependencies>

dapr-spring/dapr-spring-openfeign/spotbugs-exclude.xml

-16
This file was deleted.

dapr-spring/dapr-spring-openfeign/src/main/java/io/dapr/spring/openfeign/autoconfigure/FeignClientAnnoationEnabledCondition.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
import org.springframework.context.annotation.ConditionContext;
88
import org.springframework.core.type.AnnotatedTypeMetadata;
99

10+
import java.util.Objects;
11+
1012
public class FeignClientAnnoationEnabledCondition implements Condition {
1113
@Override
14+
@SuppressWarnings("null")
1215
public boolean matches(@NotNull ConditionContext context, @NotNull AnnotatedTypeMetadata metadata) {
13-
if (context.getBeanFactory() == null) {
14-
return false; // Return false if context or BeanFactory is null
16+
try {
17+
ConfigurableListableBeanFactory factory = Objects.requireNonNull(context.getBeanFactory());
18+
String[] beanNames = factory.getBeanNamesForAnnotation(EnableFeignClients.class);
19+
return beanNames != null && beanNames.length > 0;
20+
} catch (Exception e) {
21+
return false;
1522
}
16-
17-
String[] beanNames = context.getBeanFactory().getBeanNamesForAnnotation(EnableFeignClients.class);
18-
return beanNames != null && beanNames.length > 0; // Check for null and non-empty array
1923
}
2024
}

0 commit comments

Comments
 (0)