How Java uses reflection to find classes using specified annotations

preface

I'm a little empty recently. I want to write an annotation like the annotation in spring, and then I hope to find the class that uses the annotation I wrote. Let's introduce the implementation method

Declare that the following code is written without reading the spring source code. It is basically a blog found on the Internet and sorted out

Define annotation

Controller. java

RequestMapping. java

Using annotations

Scan all classes under the package

The following code is excerpted from an online blog

If you pass in a package name, all the following classes will be automatically scanned

Find the annotated class

Find the method annotated with requestmapping and find the injected parameters

In this way, projects written in pure servlets in Java projects can do their own annotation mapping routing, which is very convenient

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>