简介
本章实现 @RestController标注Controller、@RequestMapping注册url、@RequestBody解析json请求参数、@RequestParam标注请求入参。
创建Application启动类
首先我们需要一个入口用起来配置以及启动Tomcat。先简单的说一下Tomcat启动流程
- 初始化Tomcat(基本参数配置)
- 扫描启动类对应包下的所有类
- 扫描标注了RestController的类
- 注册Servlet(添加Handler到context中)
- 使用DispatcherServlet 统一处理所有请求,并转发到对应的Handler中进行处理
- 启动Tomcat
TomcatStartApplication
public class TomcatStartApplication {
private static final Log log = LogFactory.getLog(TomcatStartApplication.class);
public static void run(Class<?> primarySource) {
log.debug(" StartBoot begin run ... ");
try {
TomcatStarter starter = TomcatStarter.init();
//获取启动类对应包下的所有类
Set<Class<?>> classes = ClassUtil.getChildClass