您当前的位置: 首页 >  面试

xingxin666.eth

暂无认证

  • 2浏览

    0关注

    91博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

面试题:Spring中都用到了哪些设计模式?

xingxin666.eth 发布时间:2019-10-21 10:35:44 ,浏览量:2

Spring框架用到了很多设计模式,比如:工厂模式、单例模式、代理模式、模板模式、装饰器模式、责任链模式、观察者模式、策略模式、构建模式、原型模式、适配器模式等。

工厂模式

BeanFactory、ApplicationContext

单例模式

AbstractBeanFactory、DefaultSingletonBeanRegistry

Spring依赖注入Bean实例默认是单例的,Spring的依赖注入(包括lazy-init方式)都是发生在 AbstractBeanFactory 的 getBean 里,getBean 的 doGetBean 方法调用 getSingleton 进行bean的创建。

代理模式

JdkDynamicAopProxy、Cglib2AopProxy

AOP 的原理就是代理模式。

模板模式

JdbcTemplate、RestTemplate

装饰器模式

ServletRequestWrapper、SessionFactory

责任链模式

DispatcherServlet、HandlerExecutionChain

观察者模式

ApplicationEvent、ApplicationListener

策略模式

SimpleInstantiationStrategy

构建模式

BeanDefinitionBuilder

原型模式

AbstractBeanFactory

适配器模式

AdvisorAdapter、MethodBeforeAdviceAdapter、AfterReturningAdviceAdapter、ThrowsAdviceAdapter

关注
打赏
1663729395
查看更多评论
立即登录/注册

微信扫码登录

0.1237s