Skip to content

@Profile annotation is not working on @WorkflowImpl with workers-auto-discovery #2121

@hedonihilist

Description

@hedonihilist

Expected Behavior

When workers-auto-discovery is configured and @Profile annotation is used on top of @WorkflowImpl, if the profile condition doesn't match, the workflow should not be used.

Actual Behavior

Regardless of the condition in @Profile all classes annotated with @WorkflowImpl will be used.

Steps to Reproduce the Problem

  1. Create a workflow and its implementation SomeWorkflowImpl
  2. Annotate SomeWorkflowImpl with @WorkflowImpl and @Profile("!local")
  3. Run the application with local spring profile. The SomeWorkflowImpl can still be discovered and workers will be created.

Specifications

  • Version: temporal-spring-boot-autoconfigure-alpha-1.18.2.jar
  • Platform: mac

Some investigations

ClassPathScanningCandidateComponentProvider is used to scan the package to find 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;
  }

But it seems the Environment is not passed in. According to spring doc
The Environment is need to evaluate @Conditional annotations.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions