Home > Net >  How can I find out how an annotation is implemented?
How can I find out how an annotation is implemented?

Time:07-06

I want to see how Lock annotation is implemented in spring-data-jpa. I believe they use aop-alliance and intercept the annotationed methods and add some logic but I have no idea where to look for the implementation?

 // https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa
implementation group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.7.1'

Lock annotation

CodePudding user response:

Lock is an annotation and as such doesn't have any code directly attached to it.

The code "implementing it" will have to find the annotation usages and the work with that information. In order to find those places you'll search for usages of that annotation in your source code. With Lock this should lead you to this code snippet:

this.lockModeType = Lazy
                .of(() -> (LockModeType) Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(method, Lock.class)) //
                        .map(AnnotationUtils::getValue) //
                        .orElse(null));

From there you can follow it through the code.

  • Related