I am new to the concept of Java annotation. I would like to write a Java annotation as follows for my Spring boot application:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
DataType type() default null;
Class<? extends DataProcessor> dataProcessor() <--I WOULD LIKE TO ADD ONE CLASS LITERAL IMPLEMENTING DATAPROCESSOR INTERFACE DEFINED BELOW
default NullDataProcessor.class;
}
Interface DataProcessor is defined as below:
public interface DataProcessor {
String process(DataType type, Map<String, Object> input);
}
The above annotation I would like to use for a method, something like below:
@MyAnnotation(dataProcessor=MyDataProcessorImpl.class)
So here I have three questions:
- How exactly I will add a class literal as a member of Java annotation?
- How will I define multiple implementations of the interface?
- How will I define default implementation i.e. NullDataProcessor?
Could anyone please help here? Thanks.
EDIT
- From Pass method argument in Aspect of custom annotation, I got an idea regarding how to extract a value from method params with the help of an aspect. But I cannot understand, how to invoke the function:
process()
for the method params.