Does the spring context support JSR-330 Qualifier on bean instances?

Spring has its own Qualifier annotation, I think it is equivalent to javax.inject.Named annotation, which in turn is a concrete qualifier in JSR-330.

So, I wonder which version of Spring, if any, supports Qualifier?

Here is an example using the example, unfortunately, it does not work with spring -context 3.0.5:

 @Retention(RUNTIME) @javax.inject.Qualifier public @interface Version { String value(); } @Configuration public class MyConfig { @Bean("book-12") @Version("a") Book book12a() { ... } @Bean("book-12") @Version("b") Book book12b() { ... } } @Component public class UserClass { @Inject @Named("book-12") Book anybook12; @Inject @Named("book-12") @Version("b") Book book12_b; } 
+4
source share
1 answer

Yes, it supports all javax.inject.* Annotations. I myself used javax.inject.Qualifier

Btw, I assume that you want @Service or @Component instead of @Bean , and you need the Book class that spring will create.

+6
source

Source: https://habr.com/ru/post/1342806/


All Articles