zoukankan      html  css  js  c++  java
  • Spring-Aop注解应用

    注解配置

    /切面的配置

    @Aspect

    public class MyAspect {

        //切点

        @Pointcut("execution(*  com.ujiuye.service.*ServiceImpl.*(..))")

        public void pt(){}

        @Before("pt()")

        public void before(){

            System.out.println("这是前置通知");

        }

        @Around("pt()")

        public Object around(ProceedingJoinPoint  point) throws Throwable {

            System.out.println("这是环绕通知之前");

            Object obj = point.proceed();

            System.out.println("这是环绕通知之后");

            return obj;

        }

        @After("pt()")

        public void after(){

            System.out.println("这是后置通知(无论是否出现异常都会执行)");

        }

        @AfterReturning("pt()")

        public void afterReturnning(){

            System.out.println("这是后置通知,(如果有异常不走)");

        }

        @AfterThrowing("pt()")

        public void afterThrowing(){

            System.out.println("捕获到了异常");

        }

    }

     

    xml配置

    <!--让spring 扫描aop的注解,自动配置aop-->

             <aop:aspectj-autoproxy/>

             <bean class="com.ujiuye.aspect.MyAspect"/>

     

     

             <bean id="personService" class="com.ujiuye.service.PersonServiceImpl">

                      <property name="dao" ref="personDao"/>

             </bean>

             <bean id="personDao" class="com.ujiuye.dao.PersonDaoImpl"/>

  • 相关阅读:
    概率统计(DP)
    iOS中几种定时器
    微信开发笔记——微信网页登录授权,获取用户信息
    swift中通知的使用
    Swift的基础,操作符,字符串和集合类型
    NSNotificationCenter
    IOS中通知中心(NSNotificationCenter)的使用总结
    Swift观察者模式
    swift中通知的使用
    Swift
  • 原文地址:https://www.cnblogs.com/masterhxh/p/12957646.html
Copyright © 2011-2022 走看看