I have below classes.
I autowired someDao
in service class as @Autowired SomeDao someDao
.
I call the logic in service as someDao.getName(2);
SomeServiceImpl.java
public class SomeServiceImpl{
@Autowired SomeDao someDao
//call dao methods using someDao
}
SomeDao.java
public interface SomeDao{
String getName(Int id);
}
SomeDaoImpl.java
public class SomeDaoImpl implements SomeDao{
@CustomAnnotation("somevalue")
public String getName(int id){
//logic
}
}
SomeAspect.java
@Around("execution(public * *(..)) && @annotation(com.mycompany.CustomAnnotation)")
public Object procedeNext(ProceedingJoinPoint call) throws Throwable {
//Access annotation value
MethodSignature signature = (MethodSignature) call.getSignature();
Method method = signature.getMethod();
CustomAnnotation myAnnotation = method.getAnnotation(CustomAnnotation.class);
String name = myAnnotation.value();
//here i am expecting name value "somevalue" but it is returning null
}
CustomAnnotation
has @Retention(RetentionPolicy.RUNTIME)
.
In above aspect, String name = myAnnotation.value();
should give me somevalue
but it is giving null
. Any suggestion? But if I keep @CustomAnnotation("somevalue")
in interface then it gives value. Is it good to annotate interface methods?