Skip to content

Commit af51f1b

Browse files
Add NamespacesPresentCondition
1 parent df2972e commit af51f1b

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.temporal.spring.boot.autoconfigure;
2+
3+
import io.temporal.spring.boot.autoconfigure.properties.NonRootNamespaceProperties;
4+
import java.util.List;
5+
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
6+
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
7+
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
8+
import org.springframework.boot.context.properties.bind.BindResult;
9+
import org.springframework.boot.context.properties.bind.Bindable;
10+
import org.springframework.boot.context.properties.bind.Binder;
11+
import org.springframework.context.annotation.ConditionContext;
12+
import org.springframework.core.type.AnnotatedTypeMetadata;
13+
14+
/**
15+
* Condition that checks if the "spring.temporal.namespaces" property is present in the application
16+
* context.
17+
*/
18+
class NamespacesPresentCondition extends SpringBootCondition {
19+
private static final Bindable<List<NonRootNamespaceProperties>> NAMESPACES_LIST =
20+
Bindable.listOf(NonRootNamespaceProperties.class);
21+
private static final String NAMESPACES_KEY = "spring.temporal.namespaces";
22+
23+
@Override
24+
public ConditionOutcome getMatchOutcome(
25+
ConditionContext context, AnnotatedTypeMetadata metadata) {
26+
BindResult<?> namespacesProperty =
27+
Binder.get(context.getEnvironment()).bind(NAMESPACES_KEY, NAMESPACES_LIST);
28+
ConditionMessage.Builder messageBuilder = ConditionMessage.forCondition("Present namespaces");
29+
if (namespacesProperty.isBound()) {
30+
return ConditionOutcome.match(messageBuilder.found("property").items(NAMESPACES_KEY));
31+
}
32+
return ConditionOutcome.noMatch(messageBuilder.didNotFind("property").items(NAMESPACES_KEY));
33+
}
34+
}

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull Stri
6161
if (bean instanceof NamespaceTemplate && beanName.equals("temporalRootNamespaceTemplate")) {
6262
if (namespaceProperties != null) {
6363
// If there are non-root namespaces, we need to inject beans for each of them. Look
64-
// up the bean manually instead of using @Autowired to avoid circular dependencies or causing the dependency to
64+
// up the bean manually instead of using @Autowired to avoid circular dependencies or
65+
// causing the dependency to
6566
// get initialized to early and skip post-processing.
6667
//
67-
// Note: We don't use @Lazy here because these dependencies are optional and @Lazy doesn't interact well with
68+
// Note: We don't use @Lazy here because these dependencies are optional and @Lazy doesn't
69+
// interact well with
6870
// optional dependencies.
6971
metricsScope = findBean("temporalMetricsScope", Scope.class);
7072
tracer = findBean(Tracer.class);

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootNamespaceAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.springframework.context.ApplicationContextAware;
2121
import org.springframework.context.ApplicationListener;
2222
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Conditional;
2324
import org.springframework.context.annotation.Configuration;
2425
import org.springframework.context.annotation.Lazy;
2526
import org.springframework.context.event.ApplicationContextEvent;
@@ -30,8 +31,9 @@
3031
@EnableConfigurationProperties(TemporalProperties.class)
3132
@AutoConfigureAfter({RootNamespaceAutoConfiguration.class, ServiceStubsAutoConfiguration.class})
3233
@ConditionalOnBean(ServiceStubsAutoConfiguration.class)
34+
@Conditional(NamespacesPresentCondition.class)
3335
@ConditionalOnExpression(
34-
"(${spring.temporal.test-server.enabled:false} || '${spring.temporal.connection.target:}'.length() > 0) && ('${spring.temporal.namespaces:}'.length() > 0)")
36+
"${spring.temporal.test-server.enabled:false} || '${spring.temporal.connection.target:}'.length() > 0")
3537
public class NonRootNamespaceAutoConfiguration {
3638

3739
protected static final Logger log =

0 commit comments

Comments
 (0)