springday_02复习

复习

一.注解代替xml配置
    准备工作:
        4+2 + spring-aop包
        xml中导入context约束
        在xml中开启扫描包中类的注解
    注解:
        @Component("BeanName") 将对象注册到spring容器
            |-    @Controler
            |-    @Service
            |-    @Repository
        
        @Scope    指定对象的作用范围
            |- singleton
            |- prototype
            
        @Value 值类型属性注入
            
        @Autowired 自动属性注入.根据类型注入.
        @Qulifier 指定注入的对象的名称
        
        @Resource 指定对象的名称注入
        
        @PostConstruct 初始化方法
        @PreDestory    销毁方法

二.spring AOP开发
        
        aop思想: 纵向重复,横向抽取.
            |- filter中
            |- 动态代理
            |- interceptor中
            
        spring AOP: 封装了动态代理技术.来体现aop.
        
        
        springaop实现:     可以对所有对象进行代理
                |- 动态代理     代理需要实现接口.
                |- cglib代理 对目标对象继承代理.
        
        springaop名词:
                join point: 连接点.所有可以织入通知的方法.
                point cut : 切入点.需要|已经织入通知的方法.
                advice:        需要增强的代码.
                weaving:    动词.将通知应用的切点的过程.
                target: 目标对象.
                proxy:    代理对象
                aspect: 切面. 切入点+通知
                
        步骤:
            1.导包
                4+2
                2 aop+aspect
                2 aop联盟+weaving
            2.准备目标对象

            3.准备通知类
                 前置通知
                 后置通知 方法正常结束
                 环绕通知
                 异常拦截通知
                 后置通知 无论如何都执行
        
            4.配置文件中配置,导入aop约束
                1>目标对象
                2>通知对象
                3><aop:config>
                        <aop:point-cut id="切点名称" expression="execution(切点表达式)" />
                        <aop:aspect ref="通知对象名称" >
                            <aop:before method="" ponintcut-ref=""  />
                            <aop:after-returning method="" ponintcut-ref=""  />
                            <aop:around method="" ponintcut-ref=""  />
                            <aop:after-throwing method="" ponintcut-ref=""  />
                            <aop:after method="" ponintcut-ref=""  />
                        </aop:aspect>
        
        扩展:使用注解完成aop
            1.导包
                4+2
                2 aop+aspect
                2 aop联盟+weaving
            2.准备目标对象

            3.准备通知类
            4.配置文件中配置,导入aop约束
                1>目标对象
                2>通知对象
                3><aop:aspect-autoproxy> 开启注解aop
                
            5.注解
                @Aspect 指定当前类是通知类
                
                @Before 前置通知方法
                @after-returning 后置通知方法
                @around 环绕通知方法
                @after-throwing 异常拦截通知方法
                @after 后通知方法
                
                @PointCut 抽取切点表达式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值