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

假如想象 提交于 2019-12-10 15:54:27

问题


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:


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.



来源:https://stackoverflow.com/questions/5232353/does-spring-context-support-jsr-330-qualifier-on-bean-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!