首页 > 学院 > 开发设计 > 正文

spring基础-01

2019-11-14 21:54:16
字体:
来源:转载
供稿:网友
sPRing基础-01

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


上一篇:HashSet

下一篇:类集框架

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表