Spring Aop

https://docs.spring.io/spring-framework/reference/core/aop-api/pointcuts.html

Proxy - ProxyFactoryBean


        ApplicationContext context =
                new ClassPathXmlApplicationContext("aopdemo.xml");
        IDemoModel model = (IDemoModel) context.getBean("demoModelProxy");

        System.out.println(model.hello("jc.liu"));



   <bean id="demoModelProxy"
   class="org.springframework.aop.framework.ProxyFactoryBean">
       <property name="proxyInterfaces">
           <list>
               <value>tech.realcpf.spring.aop.IDemoModel</value>
           </list>
       </property>

       <property name="target" ref="demoModelImpl">

       </property>

       <property name="interceptorNames">
           <list>
                <value>demoModelArgs</value> <!-- impl MethodBeforeAdvice -->
               <value>demoModelReturn</value> <!-- impl AfterReturningAdvice -->
           </list>
       </property>
   </bean>



Auto Proxy - BeanNameAutoProxyCreator


        ApplicationContext context =
                new ClassPathXmlApplicationContext("aopdemo.xml");
        IDemoModel demoModel = context.getBean(IDemoModel.class);
        System.out.println(demoModel.hello("jc.liu"));


    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
                <property name="interceptorNames">
                    <list>
                        <value>demoModelArgs</value>
                        <value>demoModelReturn</value>
                    </list>
                </property>

        <!--        for auto match-->
        <property name="beanNames" value="*Model"></property>
    </bean>


Aspectj


    // call before
    @Before("tech.realcpf.spring.aop.aj.SystemArchitecture.service()")
    public void callBefore(JoinPoint joinPoint) {
        System.out.println("Before : " + Arrays.toString(joinPoint.getArgs()));
    }


    // call after
    @AfterReturning(pointcut = "tech.realcpf.spring.aop.aj.SystemArchitecture.service()",
            returning = "result")
    public void logResult(Object result) {
        System.out.println("after :" + result);
    }

    @Pointcut("execution(* tech.realcpf.spring.aop.aj..*(..))")
    public void service() {}


    <!-- enable aspectj -->
    <aop:aspectj-autoproxy/>