Skip to content
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

Dependency Injection does not consider parameter name as default qualifier #38671

Closed
DhavalShewale opened this issue Dec 6, 2023 · 1 comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@DhavalShewale
Copy link

DhavalShewale commented Dec 6, 2023

We recently upgraded org.springframework.boot:* from 3.1.5 to 3.2.0 and observed failures in creation of below bean:

@Bean
public Job myJob(JobRepository jobRepository, Step preProcessStep, Step processStep, Step postProcessStep) {
    return new JobBuilder("myJob", jobRepository)
            .start(preProcessStep)
            .next(processStep)
            .next(postProcessStep)
            .build();
}

Failure Message:

Parameter 1 of method myJob in com.my.package.MyJobConfig required a single bean, but 3 were found:
  - preProcessStep: defined by method 'preProcessStep' in class path resource [com/my/package/configuration/MyJobConfig.class]
  - processStep: defined by method 'processStep' in class path resource [com/my/package/configuration/MyJobConfig.class]
  - postProcessStep: defined by method 'postProcessStep' in class path resource [com/my/package/configuration/MyJobConfig.class]

With upgrade to spring boot 3.2.0 the parameter name is no longer considered as default qualifier for dependency injection.

While this can be worked around by explicitly defining a qualifier as shown below but this would mean review of all configurations and autowired dependencies where multiple beans of same interface are created. Is this change intentional or we have broken this behavior in 3.2.0?

Work Around:

@Bean
public Job myJob(JobRepository jobRepository, @Qualifier("preProcessStep") Step preProcessStep, @Qualifier("processStep") Step processStep, @Qualifier("postProcessStep") Step postProcessStep) {
    return new JobBuilder("myJob", jobRepository)
            .start(preProcessStep)
            .next(processStep)
            .next(postProcessStep)
            .build();
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 6, 2023
@bclozel
Copy link
Member

bclozel commented Dec 6, 2023

I think this is due to https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#parameter-name-discovery

You should have gotten WARN logs with Spring Boot 3.1.x about this. Please compile your code with the -parameters compiler option. See also spring-projects/spring-framework#31675

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
@bclozel bclozel added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants