Search code examples
javacdiweld

CDI compilation failure - annotation type not applicable to this kind of declaration


I have a Weld qualifier annotation declared like this:

@Qualifier
@Retention(RUNTIME)
@Target({Field, Method, Constructor})
public @interface AccountResponse {
}

My bean interface is this:

@Stateless
public interface Responder {
    /* Declares stuff */
}

The qualified implementation is this:

@AccountResponse
public class AccountResponseResponder implements Responder {
    /* Does stuff */
}

The Maven compiler says (on AccountResponseResponder.java):

annotation type not applicable to this type of declaration

I'm sure I'm missing something obvious, but what it is escapes me. Any help would be appreciated.


Solution

  • @Target({Field, Method, Constructor}) Means you can only apply this annotation to given parts of your code. In order to enable class annotation you would have to add Type to the @Target