How to skip task queues when certain spring profile is active?

Hi team, I am using spring autoconfigurer here sdk-java/temporal-spring-boot-autoconfigure-alpha at master · temporalio/sdk-java · GitHub in my projects. There’s a workers-auto-discovery option which I found very useful. But I am wondering whether it’s possible to specifically disable some task queues when using it.

Some background, say I have a workflow class like below and other workflow classes.

@WorkflowImpl(taskQueues = [TemporalConfig.EXAMPLE_TASK_QUEUE])
class SomeWorkflowImpl: SomeWorkflow {
// ....
}

In some envs the SomeWorkflow should not be executed, due to lack of permission and dependencies but other workflows should still be executed. I am wondering if there’s a way like @Profile("!env") to disable certain workflow ? I am also open to other configuration approaches to achieve this.

I am assuming here that the Temporal starter is following Spring best practices with regards to bean resolution, which would mean that Spring would do bean discovery and delegate work after that to the Temporal starter to do its magic. If this indeed is so, which under normal circumstances should be the case, would mean that you should be able to use all the Spring ways of working without interference which means profile based bean instantiation works out of the box.

However, if this is not the case, you should probably file a bug report as it would mean the Temporal starter breaks the the mental model of Spring users and impact the ability to reason about the behaviour of the starter.

Thanks for the reply frko.I have tried the @Profile approach but I am afraid it’s not working. I checked the code and it seems the Environment is not used when discovering workflows.

  private Collection<Class<?>> autoDiscoverWorkflowImplementations() {
    ClassPathScanningCandidateComponentProvider scanner =
        new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(WorkflowImpl.class));
    Set<Class<?>> implementations = new HashSet<>();
    for (String pckg : properties.getWorkersAutoDiscovery().getPackages()) {
      Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(pckg);
      for (BeanDefinition beanDefinition : candidateComponents) {
        try {
          implementations.add(Class.forName(beanDefinition.getBeanClassName()));
        } catch (ClassNotFoundException e) {
          throw new BeanDefinitionValidationException(
              "Fail loading class for bean definition " + beanDefinition, e);
        }
      }
    }
    return implementations;
  }

Maybe that’s why @Profile is not working here but I don’t know. Also created an issue in the repo here: @Profile annotation is not working on @WorkflowImpl with `workers-auto-discovery` · Issue #2121 · temporalio/sdk-java · GitHub