IOC : inversion of 縮寫,
DI:dependency injection 即在調(diào)用者中注入被調(diào)用者的實例。
AOP 面向切面編程,是代理模式的體現(xiàn)。spring默認使用JDK的動態(tài)代理,主要是代理接口,如果業(yè)務(wù)對象沒有實現(xiàn)接口,則默認CGLIB代理。
例下:
xml配置
<!-- AOP配置 --><aop:config><aop:aspect id="logAspect" ref="logService"><aop:pointcut id="targetMethod"expression="execution(* org.best.spring.aop.*.*(..))" /><aop:after pointcut-ref="targetMethod" method="doLog" /></aop:aspect></aop:config><!-- 日志服務(wù) --><bean id="logService" class="org.best.spring.xx"></bean><!-- 普通的業(yè)務(wù)bean --><bean id="targetService" class="org.best.spring.xxxxx"></bean>
實用編碼獲取bean:
// 創(chuàng)建Spring上下文 applicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "aop/TestAOP.xml" }); TargetService ts = (TargetService)ctx.getBean("targetService"); //處理業(yè)務(wù)邏輯。。。。
那么問題來了,我的目錄結(jié)構(gòu)是:

ClassPathXmlApplicationContext 是怎么讀取到 TestAOP.xml 的呢??待解決,mark
新聞熱點
疑難解答