Lenik
Lenik

Reputation: 14458

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

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;

}

Upvotes: 4

Views: 2777

Answers (1)

Bozho
Bozho

Reputation: 597046

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.

Upvotes: 7

Related Questions