Retain Your CDI Qualifiers

2014-03-29 14:26UTC

The CDI specifications is very clear in its definition of qualifiers:

A qualifier type is a Java annotation defined as @Target({METHOD, FIELD, PARAMETER, TYPE}) and @Retention(RUNTIME).

Of particular importance is the @Retention information: with the default retention, CLASS, a container's behaviour is undefined. I discovered this critical detail when creating an integration test with Spring's SpringJUnit4ClassRunner: the injection point behaved as if it was unqualified (and, technically, it was), even though the main application behaved correctly.