Does spring-context support JSR-330 Qualifier on b

2019-06-26 04:09发布

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

So, I'm wondering which version of Spring, if any, supports Qualifier?

Here is my example usage, unfortunately it doesn't 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;

}

1条回答
祖国的老花朵
2楼-- · 2019-06-26 04:34

Yes, it supports all javax.inject.* annotations. I myself have used the javax.inject.Qualifier

Btw, I assume you want @Service or @Component instead of @Bean, and you need your Book class to be made spring-managed.

查看更多
登录 后发表回答