简体   繁体   中英

How to find the code that is executed using an annotation in Spring?

Very often I use annotations in Spring. But I am curious how to find the code that is executed using a certain annotation.

An example: @PostConstruct, I know this annotation executes a method directly after the Spring Bean is initialized by the Spring Container.

However, I have no clue what java code is executed and I am not able to trace back where this code is written by clicking through my dependencies. What is the most easy way to find this code?

My tips is to use IDE search function to first search out which code location uses that annotation . As an Eclipse user on MacOS , I simply click that annotation , then hit CMD + SHIFT + G which will search out which codes use this annotation.

In case of @PostConstruct ,it quickly direct me to CommonAnnotationBeanPostProcessor 's constructor. Then simply place a breakpoint here and start your spring application in debug mode. If everything is good , it will stop at that breakpoint. At that time ,you can pay attention to the call stack which will show exactly how the code execute to that point from your application 's entry point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM