Skip to content

Determine Priority Annotations at Compile Time #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 13, 2025

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Jul 5, 2025

  • read the @Priority annotations at compile time
  • listByPriority will now sort @Primary/@Secondary beans
  • simplify duplicate type matching logic
  • Add support for using @Priority on factory @Bean methods

Resolves #854

- read the annotations at compile time
- simplify bean matching logic
- can use priority on factory beans now
@SentryMan SentryMan requested a review from rbygrave July 5, 2025 15:36
@SentryMan SentryMan self-assigned this Jul 5, 2025
@SentryMan SentryMan added enhancement New feature or request refactor labels Jul 5, 2025
@SentryMan SentryMan enabled auto-merge (squash) July 5, 2025 15:36
@SentryMan SentryMan changed the title Determine Priority annotations at compile time Determine Priority Annotations at Compile Time Jul 5, 2025
@SentryMan SentryMan added this to the 11.6 milestone Jul 5, 2025
@@ -526,7 +533,7 @@ boolean isLazy() {
}

boolean isUseProviderForSecondary() {
return secondary && !optionalType && !Util.isProvider(returnTypeRaw);
return (secondary || priority != null) && !optionalType && !Util.isProvider(returnTypeRaw);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if it's got a @Priority also wire as Provider<T> which has the effect of only instantiating when needed.

Needed by .. being the highest priority or BeanScope#list or injecting a List/Set/Map of that type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the appearance of a priority annotation invites the possibility that a higher priority bean might exist

Copy link
Contributor

@rbygrave rbygrave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this PR.

I think it's nice to merge the Priority in with Primary and Secondary.

@SentryMan SentryMan merged commit f13ffcc into avaje:master Jul 13, 2025
5 checks passed
@SentryMan SentryMan deleted the priority branch July 13, 2025 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change @Priority to be used as wiring priority / merge concept with @Primary and @Secondary
2 participants