當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
代理模式在Spring 源码中的应用
生活随笔
收集整理的這篇文章主要介紹了
代理模式在Spring 源码中的应用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
先看ProxyFactoryBean 核心的方法就是getObject()方法,我們來看一下源碼:
public Object getObject() throws BeansException {initializeAdvisorChain();if (isSingleton()) {return getSingletonInstance();}else {if (this.targetName == null) {logger.warn("Using non-singleton proxies with singleton targets is often undesirable. " +"Enable prototype proxies by setting the 'targetName' property.");}return newPrototypeInstance();} }在getObject()方法中,主要調(diào)用getSingletonInstance()和newPrototypeInstance();在Spring 的配置中,如果不做任何設置,那么Spring 代理生成的Bean 都是單例對象。如果修改scope 則每次創(chuàng)建一個新的原型對象。newPrototypeInstance()里面的邏輯比較復雜,我們后面的課程再做深入研究,這里我們先做簡單的了解。
Spring 利用動態(tài)代理實現(xiàn)AOP 有兩個非常重要的類,一個是JdkDynamicAopProxy 類和CglibAopProxy 類
?
總結
以上是生活随笔為你收集整理的代理模式在Spring 源码中的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CGLib 和JDK 动态代理对比
- 下一篇: Spring 中的代理选择原则