Skip to content

Detect clash with multiple @Bean methods returning same type #781

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 1 commit into from
Mar 26, 2025

Conversation

rbygrave
Copy link
Contributor

@rbygrave rbygrave commented Mar 25, 2025

Given a @Factory with 2 or more bean methods that return the same type, and effectively clash on qualifier name (typically missing) then make this a compilation error.

The error suggests to add a @Named or qualifier annotation to resolve the issue.

Example:

@Factory
class MyFactory {

  @Bean
  BFace one() {
    ...
  }

  @Bean
  BFace two() {
    ...
  }

Given a @factory with 2 or more bean methods that return the same type, and effectively clash on qualifier name (typically missing) then make this a compilation error.

The error suggests to add a @nAmed or qualifier annotation to resolve the issue.

Example:
```java
@factory
class MyFactory {

  @bean
  BFace one() {
    ...
  }

  @bean
  BFace two() {
    ...
  }
```
@rbygrave
Copy link
Contributor Author

An variation to this would be to give the @Bean a default qualifier based on the method name.

So for example:

@Bean BFace one() { ...

... would get the default qualifier name of one from the method name.

Copy link
Collaborator

@SentryMan SentryMan left a comment

Choose a reason for hiding this comment

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

is this a thing that happens?

@rbygrave
Copy link
Contributor Author

is this a thing that happens?

I don't know if other people hit this, but I did hit it yesterday accidentally myself when I was looking to inject multiple Filter's via a Factory. I'm hoping people haven't hit it because it's a bit subtle and confusing when it occurs.

@SentryMan
Copy link
Collaborator

looking to inject multiple Filter's via a Factory.

I just use avaje http for filters I guess

@rbygrave rbygrave self-assigned this Mar 26, 2025
@rbygrave rbygrave added this to the 11.4 milestone Mar 26, 2025
@rbygrave rbygrave merged commit b4f4dba into master Mar 26, 2025
13 checks passed
@rbygrave rbygrave deleted the feature/detect-bean-method-clash branch March 26, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants