Java – how does Tomcat recognize servlets specified with annotations?

Before servlet 3.0, you need to provide URL patterns and servlet classes in web Configure servlet. XML Whenever a request for a servlet is sent, Tomcat will be on the web Search the servlet class in XML and call doget or dopost according to the type of request

Thank you in advance

Solution

Tomcat scans web applications for class files (in Web - inf / classes and jars) Then pass the class file to the local copy of the heavily edited package rename of the Apache common byte code engineering library (BCEL) The BCEL version of Tomcat is optimized to handle only the bytecode part of Tomcat's interest (annotation, superclass, if any, implements the interface), and skip the rest as soon as possible BCEL reads class files directly from disk

Tomcat carefully caches the results of BCEL, so even for the most complex class hierarchy, each class is processed only once. If comments (including comments inherited from super classes), post-processing is not required to obtain the complete list of any courses

The annotation scan also checks for matches with SCI's @ handlestypes annotation

Scanning the comments of each class is expensive, but you do it (which is one of the reasons why I don't like this special feature) Tomcat's implementation went through several iterations before implementing the efficient implementation it now uses

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
分享
二维码
< <上一篇
下一篇>>