【发布时间】:2019-09-17 13:30:51
【问题描述】:
我创建了 2 个自定义弹簧 @annotations。我需要在方法级别而不是类级别定义这些注释的顺序。 @order 是否也适用于方法级别?
@Aspect
@Component
public class ABC {
private ThreadLocal<logDTO> myThreadLocal;
@Before("@annotation(CommunicationLogInit)")
public void CampaignLogsInit(){
myThreadLocal = new ThreadLocal<logDTO>();
myThreadLocal.set(new logDTO());
}
@Around("@annotation(CommunicationAudit)")
public Object generateLog(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature)joinPoint.getSignature();
Method method = signature.getMethod();
int counter = 0;
for(Parameter parameter : method.getParameters()){
Annotation eventName = parameter.getAnnotation(EventName.class);
Annotation rtnInfo = parameter.getAnnotation(RtnInfo.class);
if(eventName!=null){
System.out.println(joinPoint.getArgs()[counter]);
myThreadLocal.get().setName("ABC");
}
}
}
}
【问题讨论】:
-
你能显示你的自定义注释代码吗
-
欢迎来到 SO。如果您了解MCVE 是什么,然后将您的问题变成一个问题,那就太好了。否则人们不得不猜测你在问什么。所以让我猜猜:您的方面确实有效,两种建议方法都被触发,但不是按照您喜欢的顺序?你想知道你是否可以使用
@Order?