Моя точка зрения на аннотации. Я хочу получить ThreadLocal Field, но я всегда получаю ноль.
Как я могу получить ThreadLocal Field?
это мой код
`@Component
public class RegistrationFacade {
/**
my aspect cut @Notification,and get ThreadLocal field.but i get null
*/
ThreadLocal<NotificationEvent> event;
@Notification(event =
NotificationEvent.INSERT_REFERRAL_REGISTRATION_EVENT)
public Pair<Integer, String>
insertReferralRegistration(VillageReferralRegistrationRequest request) {
xxxx
}`
/*
* this is my aspect,my logic is not implement, i can get fieldClassName but value is null. how can i get value
*/
@After("@annotation(my.Notification)")
public void cutNotification(JoinPoint joinPoint) throws Throwable {
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Notification notification = methodSignature.getMethod().getAnnotation(Notification.class);
Object target = joinPoint.getTarget();
String propName = notification.event();
Field field = target.getClass().getDeclaredField(propName);
field.setAccessible(true);
Object eventObj = field.get(target);// this is null
String fieldClassName = field.getType().getSimpleName();//this is ThreadLocal