Я использую Spring AOP, как я могу получить значения из аннотации. Вот моя аннотация:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Inherited
@Documented
public @interface ExecutionMethodProfiler
{
String value() default "defaultValue";;
}
вот мой XML:
<aop:aspectj-autoproxy/>
<aop:config>
<aop:aspect ref="methodProfiler">
<aop:pointcut id="serviceMethod"
expression="(execution(* com.old..*(..)) or execution(* com.test..*(..))) and @annotation(com.test.profiler.ExecutionMethodProfiler)" />
<aop:around pointcut-ref="serviceMethod" method="profile"/>
</aop:aspect>
</aop:config>
И это мой сервисный метод:
public void profile(ProceedingJoinPoint jointPoint) throws Throwable {}
на данный момент я могу получить значения, используя этот код:
MethodSignature signature = (MethodSignature) jointPoint.getSignature();
System.out.println(signature.getMethod().getAnnotation(ExecutionMethodProfiler.class).value());
Мне это не нравится, есть ли лучший способ?