diff --git a/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java b/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java
index 0baf28177..a1ddbe794 100644
--- a/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java
+++ b/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorClientAutoConfiguration.java
@@ -18,6 +18,7 @@
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
+import org.conductoross.conductor.sdk.Conductor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -61,6 +62,17 @@ public ConductorClient conductorClient(ClientProperties properties) {
return builder.build();
}
+ /**
+ * Native workflows over the configured client (an Orkes {@code ApiClient} with keys when one is
+ * configured). Closing it stops the workers it started; the client bean is left to Spring.
+ */
+ @Bean(destroyMethod = "close")
+ @ConditionalOnBean(ConductorClient.class)
+ @ConditionalOnMissingBean
+ public Conductor conductor(ConductorClient client) {
+ return Conductor.of(client);
+ }
+
@Bean
@ConditionalOnBean(ConductorClient.class)
@ConditionalOnMissingBean
diff --git a/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorWorkflowAutoConfiguration.java b/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorWorkflowAutoConfiguration.java
new file mode 100644
index 000000000..283f6d0b0
--- /dev/null
+++ b/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorWorkflowAutoConfiguration.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020 Conductor 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
+ *
+ * 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 com.netflix.conductor.client.spring;
+
+import org.conductoross.conductor.sdk.Conductor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.AutoConfigureOrder;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.Ordered;
+import org.springframework.core.env.Environment;
+
+/**
+ * Hosts the application's native workflows: every class under the application's packages with a
+ * {@code @Workflow} method. Set {@code conductor.workflows.enabled=false} in a service that only
+ * starts workflows.
+ */
+// Last, like the other Conductor auto-configurations: an earlier position would also move the
+// client auto-configuration ahead of the Orkes one, and both would then define a TaskClient.
+@AutoConfiguration(after = ConductorClientAutoConfiguration.class)
+@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
+@ConditionalOnBean(Conductor.class)
+@ConditionalOnProperty(prefix = "conductor.workflows", name = "enabled", matchIfMissing = true)
+public class ConductorWorkflowAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ public ConductorWorkflowHost conductorWorkflowHost(Conductor conductor,
+ ConfigurableListableBeanFactory beanFactory,
+ Environment environment) {
+ return new ConductorWorkflowHost(conductor, beanFactory, environment);
+ }
+}
diff --git a/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorWorkflowHost.java b/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorWorkflowHost.java
new file mode 100644
index 000000000..9436d4bf9
--- /dev/null
+++ b/conductor-client-spring-boot4/src/main/java/com/netflix/conductor/client/spring/ConductorWorkflowHost.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2020 Conductor 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
+ *
+ * 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 com.netflix.conductor.client.spring;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.conductoross.conductor.sdk.Conductor;
+import org.conductoross.conductor.sdk.Workers;
+import org.conductoross.conductor.sdk.Workflow;
+import org.conductoross.conductor.sdk.internal.TaskStubs;
+import org.springframework.aop.support.AopUtils;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.DependencyDescriptor;
+import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.MethodParameter;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+
+import com.netflix.conductor.sdk.workflow.task.WorkerTask;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * Finds the classes with {@code @Workflow} methods under the application's packages and hosts
+ * them once the application has started, stopping before the context closes.
+ *
+ *
A workflow class need not be a bean. Each replay gets a new instance: a constructor parameter
+ * of a class with {@code @WorkerTask} methods gets a stub whose calls schedule those tasks, and
+ * any other parameter or {@code @Autowired} field is injected from the context. A field holding a
+ * real task object is rejected, since its calls would run in the workflow on every replay. Task beans keep running on the worker auto-configuration's executor; this only
+ * registers their task definitions, from the {@code @WorkerTask} attributes.
+ *
+ *
Properties under {@code conductor.workflows}: {@code worker-id} and {@code dev-mode}. Per
+ * workflow, read from the environment: {@code conductor.workflow..threadCount}, {@code
+ * pollingInterval}, {@code pollTimeout}, {@code paused} and {@code continuationTimeout}, or {@code
+ * conductor.workflow.all.*} (see {@link Workers}).
+ */
+@Slf4j
+public class ConductorWorkflowHost implements SmartLifecycle {
+
+ private final Conductor conductor;
+ private final ConfigurableListableBeanFactory beanFactory;
+ private final Environment environment;
+ private volatile Workers workers;
+
+ public ConductorWorkflowHost(Conductor conductor, ConfigurableListableBeanFactory beanFactory,
+ Environment environment) {
+ this.conductor = conductor;
+ this.beanFactory = beanFactory;
+ this.environment = environment;
+ }
+
+ @Override
+ public void start() {
+ Set> types = workflowTypes();
+ if (types.isEmpty()) {
+ log.info("No @Workflow classes under {}", packages());
+ return;
+ }
+ Workers w = conductor.workflows();
+ String workerId = environment.getProperty("conductor.workflows.worker-id");
+ if (workerId != null) {
+ w.workerId(workerId);
+ }
+ w.settings(environment::getProperty);
+ w.devMode(environment.getProperty("conductor.workflows.dev-mode", Boolean.class, false));
+ types.forEach(type -> host(w, type));
+ w.taskDefinitions(taskBeans().toArray());
+ workers = w.start();
+ }
+
+ @Override
+ public void stop() {
+ Workers w = workers;
+ workers = null;
+ if (w != null) {
+ w.close();
+ }
+ }
+
+ @Override
+ public boolean isRunning() {
+ return workers != null;
+ }
+
+ private void host(Workers w, Class type) {
+ w.workflows(type, () -> {
+ // task classes come as stubs, so their calls schedule tasks; anything else from the context
+ T workflow = TaskStubs.newWorkflow(type,
+ p -> beanFactory.resolveDependency(new DependencyDescriptor(MethodParameter.forParameter(p), true), null));
+ beanFactory.autowireBean(workflow);
+ return workflow;
+ });
+ }
+
+ private List packages() {
+ return AutoConfigurationPackages.has(beanFactory) ? AutoConfigurationPackages.get(beanFactory) : List.of();
+ }
+
+ Set> workflowTypes() {
+ ClassPathScanningCandidateComponentProvider scanner =
+ new ClassPathScanningCandidateComponentProvider(false, environment);
+ scanner.addIncludeFilter((reader, factory) ->
+ reader.getAnnotationMetadata().hasAnnotatedMethods(Workflow.class.getName()));
+ Set> types = new LinkedHashSet<>();
+ for (String pkg : packages()) {
+ for (BeanDefinition candidate : scanner.findCandidateComponents(pkg)) {
+ types.add(ClassUtils.resolveClassName(candidate.getBeanClassName(), beanFactory.getBeanClassLoader()));
+ }
+ }
+ return types;
+ }
+
+ /** The same beans the worker auto-configuration polls: components with {@code @WorkerTask} methods. */
+ private List