IOC : inversion of 缩写,
DI:dependency injection 即在调用者中注入被调用者的实例。
AOP 面向切面编程,是代理模式的体现。spring默认使用JDK的动态代理,主要是代理接口,如果业务对象没有实现接口,则默认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><!-- 日志服务 --><bean id="logService" class="org.best.spring.xx"></bean><!-- 普通的业务bean --><bean id="targetService" class="org.best.spring.xxxxx"></bean>
实用编码获取bean:
// 创建Spring上下文 applicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "aop/TestAOP.xml" }); TargetService ts = (TargetService)ctx.getBean("targetService"); //处理业务逻辑。。。。
那么问题来了,我的目录结构是:
ClassPathXmlApplicationContext 是怎么读取到 TestAOP.xml 的呢??待解决,mark
新闻热点
疑难解答