当前位置:网站首页>@How to resolve controller and requestmapping
@How to resolve controller and requestmapping
2022-06-11 12:58:00 【yingyinqixian】
1, annotation
Click in @RestController You can see it in it @Controller and @RsponseBody annotation , How does this annotation identify our request path , It is mainly divided into two steps , The first step is to spring initialization , After the project is started and initialized , The second step is to process user requests , adopt springmvc Medium dispatchservlet call org.springframework.web.servlet.handler.AbstractHandlerMapping#getHandler Method returns the execution chain HandlerExecutionChain, Get into getHandler Method will find that it will call org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#getHandlerInternal Method

2, initialization
2.1,AbstractHandlerMethodMapping
First look at abstract classes AbstractHandlerMethodMapping, Realized InitializingBean Interface rewrites afterPropertiesSet,InitializingBean There is an important way afterPropertiesSet


2.2,InitializingBean
When a class implements this interface ,Spring After starting , initialization Bean when , If so Bean Realization InitialzingBean Interface , Automatically called afterPropertiesSet() Method , Complete some user-defined initialization operations , stay BeanFactory After initializing this bean, And the bean Is called once after the parameters of are successfully injected afterPropertiesSet() Method ,InitializingBean There is a function similar to XML Configuration in profile init-method,afterPropertiesSet() stay init-method Previous call , see AbstractAutowireCapableBeanFactory Class invokeInitMethods Method . Similar interfaces include SmartInitializingSingleton

1,SmartInitializingSingleton Only for single cases bean,InitializingBean No requirements . Can not be used for lazy loading bean.
2,SmartInitializingSingleton In all cases Bean Are called after initialization ,InitializingBean Is each bean After the initialization is completed, the .

2.3,detectHandlerMethods
Click in AbstractHandlerMethodMapping Medium detectHandlerMethods Method , With UserController For example

Get into detectHandlerMethods The method 
Judge handler Whether to belong to string type , If it is obtained from the context handler Of class, If not obtained directly class

Judge whether it includes cglib Bytecode separator , If you include , Get the... Of the bytecode
Super class bytecode and the class bytecode is not Object And back to

MethodIntrospector.selectMethods Method transfer 2 Parameters , The first parameter bytecode , The second parameter MetadataLookUp It's a function interface ,@FunctionalInterface Decorate similar interfaces Consumer and Function,java8 Many such function interfaces are provided , Of course, you can also customize the implementation ,inspect Methods in selectMethods Execute... On call , adopt this.getClass().isAnonymousClass() You can determine whether it is an anonymous inner class , Anonymous classes that implement interfaces , Grammar format :new < Parent class or interface > < class >, The advantage here is code reuse ,MethodIntrospector Is an abstract class that provides a common set of implementations , Subclass inheritance can use this method in general , Different implementations are implemented in subclasses , Similar functions are implemented by abstract method subclasses 、 Function interface callback, etc , This scenario belongs to function callback ; Get into MethodIntrospector class selectMethods Method , return map

Back to detectHandlerMethods Methods registerHandlerMethod Interface method , Get into registerHandlerMethod Methods the internal


3, request
边栏推荐
- How can I use a domain name to access a website?
- .net core 抛异常对性能影响的求证之路
- How does the beauty salon management system solve the three problems of store operation?
- Tawang food industry insight | China's dairy market analysis, competition pattern, development trend and thinking
- Luo Jing: connection Efficiency Optimization Practice
- qq内拉起支付宝h5支付功能
- Seckill multi-level cache ----- product details page
- 如何学会花钱
- 2022年618投影仪保值品牌榜,当贝投影闲鱼保值率排行TOP1
- From quic to TCP
猜你喜欢

两件小事,感受到了和大神的差距

How Oracle exports data to CSV (Excel) files

How does the beauty salon management system solve the three problems of store operation?

1. Thread Basics

Security mechanism of verification code in seckill

netstat 命令详解

@Controller和RequestMapping如何解析的

罗景:连接效率优化实践

4K投影仪哪款性价比最高,当贝X3 Pro高亮128G存储618值得看

How about Lenovo Xiaoxin 520? Which is more worth buying than dangbei D3x?
随机推荐
Unity 游戏保护“大练兵”,一文读懂游戏事前防御
字节真的是宇宙尽头吗?
知物由学 | 行为时序建模在社交引流黑产识别中的应用
Matrix elimination game
.net core 抛异常对性能影响的求证之路
换种方式实现阖家团圆,2022旗舰投影坚果J10S被种草
Record a JVM GC process
What are the profit sources of mother and baby stores?
4. Locksupport and thread interruption
2020.10.27 北京阿里大文娱一面总结
Redis数据类型日常使用场景
Redis RDB和AOF
求你了,不要再在对外接口中使用枚举类型了!
qq内拉起支付宝h5支付功能
【接口】看接口路径 查接口
Syntax of SQL
记录一次jvm GC过程
Oracle 将数据导出到CSV(Excel)文件的方法
imx6ul开发板移植主线u-boot之EMMC启动流程
Kehai Rongsheng & zhenghang will jointly welcome the future of digital intelligence with informatization driven management upgrading