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

Add Support for properties and @NonBinding in javax.inject.Qualifier annotations #4769

Closed
ghillert opened this issue Jan 4, 2021 · 3 comments
Labels
status: pr submitted A pull request has been submitted for the issue
Milestone

Comments

@ghillert
Copy link

ghillert commented Jan 4, 2021

I am trying to use a custom @qualifier annotation which itself contains qualifying elements/properties together with InjectionPoint. Although the respective @Bean definition looks almost exactly the same, the observed behavior, however, is different from Spring Framework. It is actually quite contrary.

Micronaut is ignoring any elements/properties of the Qualifier annotation in determining the proper @Bean method. For instance the following (very contrived) code in Spring would work but fails in Micronaut:

@Bean
@Greeting(language = Language.DE)
@Prototype
public String greetingDE(InjectionPoint injectionPoint) {
    return handleInjectionPoint(injectionPoint);
}

@Bean
@Greeting(language = Language.EN)
@Prototype
public String greetingEN(InjectionPoint injectionPoint) {
    return handleInjectionPoint(injectionPoint);
}

@Bean
@Greeting(language = Language.ES)
@Prototype
public String greetingES(InjectionPoint injectionPoint) {
    return handleInjectionPoint(injectionPoint);
}

I wonder if Micronaut could be aligned more closely with CDI in that regard and not only consider properties but also the @NonBinding annotation to provide comprehensive qualifier support.

Ideally, it would be desirable if also Spring and Micronaut would align in this regards as the targeted functionality is de facto identical. For reference please see 2 issues I have created against Spring Framework:

Add Support for @NonBinding in javax.inject.Qualifier annotations
spring-projects/spring-framework#26302

Add ability to ignore certain Qualifier Annotations using CustomAutowireConfigurer
spring-projects/spring-framework#26305

It certainly does not help the matter that @nonbinding is not part of JSR-330 (Dependency Injection for Java). Rather it is part of JSR-299 (Java Contexts and Dependency Injection).

This issue might be related to issue CDI Alignment Tasks.

For further reference:

Java EE JavaDoc - Annotation Type Nonbinding
https://javaee.github.io/javaee-spec/javadocs/javax/enterprise/util/Nonbinding.html

Advanced Using @Nonbinding to combine a configuration annotation and a qualifier annotation into one annotation
https://dzone.com/articles/cdi-di-p2

@graemerocher
Copy link
Contributor

Thanks for the feedback, I will include it in #4658

@ghillert
Copy link
Author

Thanks! By the way, speaking of CDI Alignment Tasks: 6 years ago Juergen Hoeller mentioned some activity around a JSR-330 v2. This might technically be a good candidate for some improved standardization.

spring-projects/spring-framework#17723

@graemerocher graemerocher added this to the 3.0.0 milestone Mar 11, 2021
@graemerocher
Copy link
Contributor

Fixed in #5075

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pr submitted A pull request has been submitted for the issue
Projects
None yet
Development

No branches or pull requests

2 participants