Git Product home page Git Product logo

myspring's Introduction

MySpring

Spring的简易实现

模仿学习Spring源码,实现了IOC和AOP的基本功能,简化了复杂的继承及接口逻辑,忽略了大部分细节处理,部分类与源码命名相同, 有些类作了命名的简化。

功能实现

IOC

  • Bean的扫描,按照@ComponentScan指定路径递归扫描文件夹,遇到@Commponent注解的类则创建对应BeanDefinition加入BeanDefinitionMap中.
  • Bean的主要生命周期,包括创建、实例化、依赖注入、初始化、Aware接口回调、后置处理器回调等.
  • 三级缓存解决单例Bean的循环依赖问题,singletonObjects存放成品、earlySingletonObjects存放半成品、singletonFactories存放早期工厂.

AOP

  • 只支持@Before@AfterReturning两种通知.
  • 切点的简单匹配,只支持@annotation注解的形式.
  • @Aspect标记的高级Advisor向低级Advisor的转变, 利用AdvisorFactory实现, 只支持高级Advisor.
  • AnnotationAwareAspectJAutoProxyCreator后置处理器进行代理的创建, findCandidateAdvisors()寻找容器中的所有Advisor, 只查找一次然后缓存起来; findEligibleAdvisors()查找当前类匹配的Advisor; wrapIfNecessary()如果有匹配的Advisor则创建动态代理, 否则不创建.
  • 调用时通过适配器将Advisor转化为Interceptor, 通过Interceptor调用Advice.
  • Invocation进行Interceptor的责任链递归调用, 未实现排序功能.
  • 通过JDK创建动态代理, 未实现cglib动态代理.
  • 循环依赖时通过getEarlyBeanReference()提前创建代理, 避免引用到原对象.

测试

  • IOC及AOP测试:test/Test.java
  • 循环依赖测试:test/circularDependencyTest/Test.java

myspring's People

Contributors

kingfly77 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.