Back to all reviewers

Spring DI precedence rules

quarkusio/quarkus
Based on 2 comments
Java

When developing Quarkus extensions that interact with classes containing Spring annotations (like `@Service`, `@Component`, etc.), ensure your extension respects Spring DI's scope definitions by setting appropriate annotation transformer priorities.

Spring Java

Reviewer Prompt

When developing Quarkus extensions that interact with classes containing Spring annotations (like @Service, @Component, etc.), ensure your extension respects Spring DI’s scope definitions by setting appropriate annotation transformer priorities.

Spring DI extension uses the default priority of 1000 for its transformers. If your extension also adds scopes or bean-defining annotations to classes, it should use a lower priority value to allow Spring annotations to take precedence.

For example, when implementing an annotation transformer that adds scopes:

@Override
public int priority() {
    return 500; // Lower priority than Spring DI's 1000
}

Alternatively, if using the AutoAddScopeBuildItem pattern:

@BuildStep
AutoAddScopeBuildItem autoAddScope() {
   return AutoAddScopeBuildItem.builder()
      .containsAnnotations(YOUR_ANNOTATIONS) 
      .defaultScope(BuiltinScope.YOUR_SCOPE)
      .priority(500) // Lower than Spring DI's priority
      .build();
}

This approach prevents conflicts when multiple extensions try to add “auto” scopes to the same classes, ensuring Spring annotations are properly honored in the application.

2
Comments Analyzed
Java
Primary Language
Spring
Category

Source Discussions