Hand roll up a HTTP framework: support sprng, MVC, IOC, AOP, interceptor, configuration file read

JavaGuide 2020-11-13 10:05:12
hand roll http framework support

https://github.com/Snailclimb/jsoncat : Imitation Spring Boot But it's different from Spring Boot A lightweight of HTTP frame

From the last time I reported to my friends the simple version of “Spring Boot” It's been half a month since . How fast time flies !


In this half month , my HTTP The framework already supports AOP、 Interceptor ( It's also AOP A kind of )、 Property file read and other functions .

Current words , Whole HTTP The framework has basically all the functions I wanted to achieve in the first place . It's a promise , A good beginning and a good ending .

The specific implementation of the function is as follows :

Many readers may find it easier for me to write . however , Tell the truth , I also encountered a lot of problems in the process of writing . In order to solve some problems in writing this framework , I stayed up a lot of nights , I got up early many times .

I'm not a fan Qing . In general , I'm usually at night 9 Play some king's glory after 30:30 , here we are 12 I went to bed around 1:00 . In the morning , I'm usually 8 Get up around o'clock . Almost every day .

however , Write this HTTP Frame time , I remember there was 3 I stayed up late into the morning 2 P.m. . Yes 2 This morning , Because there is “ inspiration ”, I 5 How long did it take to get up and write code .

Say that , It's not for the sake of sympathy, to make people think how hard I write , It's not about how hard I try .

These are just ordinary experiences ! I think most programmers have experienced :

  • In the dead of night , Suddenly there was something wrong with my own code , You don't want to sleep if you don't solve it .
  • One morning , Wake up suddenly , I'm inspired , Turn on the computer and start writing code .

however , I really don't recommend staying up late ! Well, I'll do it myself , Every time I stay up late, I will be depressed the next day or even the third day , Seriously affect efficiency . It's just the short-term effect of staying up late , If your work and rest are not healthy for a long time , It must have done a lot of damage to the body .

All the reasons are clear , however , Most of them are like me , Or occasionally stay up late .


The directory structure of the whole framework is as follows :

  • The implementation part of the framework is organized according to different functional modules , intuitive .
  • Provides a complete framework using examples , And I've written tests for it .


The charm of open source is that people can give feedback on your project , also , Meet friends who are interested in your project , They'll also help you refine and develop projects together .

take jsoncat Come on .jsoncat After open source , One is called “hellohello-tom” My elder brother joined in to help develop .

tom Brother code is very good , help jsoncat Many functions have been realized ! Thank you very much very much ! Love you ! my dear friend !

We often communicate on wechat because of this project , Maybe that's the charm of programming ! Ha ha ha !

I seldom chat on wechat , But because of this open source project, I talked with my brother a lot .

Cut two pictures at random :

I think a project development is more taboo only their own . Everyone has limitations in their thinking , It's hard to find out where your code needs to be improved and what's wrong with it .

It also explains why Code Review( Code review ) It's so important in software development .

adopt Code Review Can be very effective in improving the overall quality of code , Because it will help us find bad smell in the code and possible problems .


Actually , It doesn't take much time to implement the function alone . Most of the time , I spent all my time refactoring existing code .

After all, I am HTTP One of the main purposes of the open source framework is to learn from the partners in need , I have to make sure that the code I write is readable .​

So , I set the following principles for myself in the process of writing code :

  1. The basics : With the least amount of code Write clearly You don't have to use one more line of code .
  2. Don't abuse design patterns : When I first wrote code , Especially like abusing design patterns . What design patterns have you learned , It's like using your own project immediately , Even if this design pattern is not suitable for the current business scenario . It's really a bad habit , however , I'm writing this HTTP When framing, I deliberately avoided this problem . Current words , The whole framework only uses singleton pattern 、 Factory mode 、 Strategy model and responsibility chain model .
  3. Keep the code structure clear : It's open source code , Clear code structure can greatly reduce the difficulty for others to understand the code .
  4. Carefully extract tool classes : When I first wrote this framework , I took a lot of tools . In the end, we found many methods in the tool class , Actually, it's only used in one place , And it will only be used in this place in the future . This is the time , I think the best way is to , Put these tool class methods in the only class that uses this method . In this way, the overall code structure will be clearer .
  5. No show of skill : When I first wrote code , I love show skills . for instance Java8 When it wasn't popular , I always want to write code with Java 8 Of Lambda expression 、 Functional interface and other new features . At that time , When working on projects with teachers , Other students will think that I write a special force , Because they think it's a long time before they can understand . however , I now feel that the practice at that time was actually different from software development / The nature of programming , The essence of programming is not to reduce the amount of code , It's about writing code that is easy for others to understand , Write systems that are easier to maintain . The code you write is not just for you to see , You have to make it understood , Reduce the cost of reading and learning for others . This does not contradict everything I said in the first point .

Let's talk about it today ! It's not too early !

My open source project recommends

  1. JavaGuide :「Java Study + Interview guide 」 One covers most Java The core knowledge that programmers need to master . Get ready Java interview , The preferred JavaGuide!
  2. guide-rpc-framework :A custom RPC framework implemented by Netty+Kyro+Zookeeper.( Based on a Netty+Kyro+Zookeeper Implemented customization RPC frame - The detailed implementation process and related tutorials are attached )
  3. jsoncat : Imitation Spring Boot But it's different from Spring Boot A lightweight of HTTP frame
  4. programmer-advancement : Programmers should have some good habits + Interview must know !
  5. springboot-guide :Not only Spring Boot but also important knowledge of Spring( It's not just SpringBoot also Spring Important knowledge points )
  6. awesome-java :Collection of awesome Java project on Github(Github It's great Java Open source project collection ).

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple