Writing in the front
At this point, people in our company are almost gone, the reason is very simple ah, tomorrow’s New Year’s day, but before the holiday will not work overtime, very nice, I am an intern, today to share with you a springboot custom annotation technology article.
That’s a great note
In the process of development, we must have used or heard the notes, adding a note is fine, but why so powerful, the bottom of the gourd in the end what medicine, today we will cut the gourd to see gourd gourd.
Can’t live without new Java features
When using SpringBoot annotations, I feel like wow, spring is so powerful, but I do not know that clicking on the source code is due to JDK annotations. First look at the Component annotations, the above three are JDK annotations, also known as meta-annotations. What is @Indexed? It’s not Indexed yet.
Something curious
In fact, there is an awesome operation. The function of this annotation, where is the logic to write it? At this time, AOP thought can be kind to enter the stage, we can solve it through a faceted thought. Dynamic proxy is implemented in JDK or CGLIB, so the question is, how is it implemented in JDK or CGLIB? I don’t know.
Powerful AOP
Interview, often asked questions about AOP, but I always said that AOP defined a section can achieve the log function, every day is so answer, I have a little impatient, today to point special, or log, but this time with annotations.
Since AOP is implemented with annotations, the first thing you need to do is define an annotation.
Annotations are defined, and the parameters are briefly described. Here, we will focus on how to customize annotations.
lementType.METHOD
This means using annotations on methods
RetentionPolicy.RUNTIME
This is run time
@Documented
This is what generates the Javadoc
The annotation is defined, so what happens next, of course, is to make the annotation work. How does it work? AOP can now appear.
There are so many notes inside, I will not bb.
Then you can test it. Is not very simple, I also think, difficult things are others to achieve good… If you have the ability, you can look into the underlying implementation of @Aspect, or we can discuss it together when I publish the article. Go away and test it.
With one controller, you just add one@MyLog
Can.
You can clearly see that it has taken effect, there are many magical annotations, this is just a primer, today’s content is here, I wish everyone a happy New Year’s day! See you next time