zoukankan      html  css  js  c++  java
  • ASPCTJ

    ublic interface ISomeService {
        public void doSome();
    
        public String dade();
    }
    复制代码
    复制代码
    public class SomeService implements ISomeService {
        //核心业务
        public void doSome(){
            System.out.println("我们都要找到Java开发工作,薪资6,7,8,9,10K");
        }
    
        public String dade() {
            System.out.println("==================");
            return "add";
        }
    
    }
    复制代码
    复制代码
    复制代码
    复制代码
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.*;
    
    /**
     * Created by QiuShao on 2017/7/31.
     */
    @Aspect
    public class MyAspect {
        /*前置增强*/
        @Before(value = "execution(* *..spring17.*.*(..))")
        public void before(){
            System.out.println("前置增强");
        }
    
        /*后置增强*/
        @AfterReturning(value = "execution(* *..spring17.*.*(..))")
        public void after(){
            System.out.println("后置增强");
        }
        /*环绕增强*/
        @Around(value = "execution(* *..spring17.*.*(..))")
        public Object around(ProceedingJoinPoint proceed) throws Throwable {
            System.out.println("环绕前");
            Object result=proceed.proceed();
            System.out.println("环绕后");
            if(result!=null){
               return result;
                /*String str=(String)result;
                return str.toUpperCase();*/
            }else {
                return null;
            }
        }
    }
    复制代码
    复制代码

    配置文件

    复制代码
    复制代码
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd
    ">
        <!--01.目标对象-->
        <bean id="someService" class="cn.bdqn.spring17.SomeService"></bean>
    
        <!--02.增强 通知-->
        <bean class="cn.bdqn.spring17.MyAspect"></bean>
    
        <aop:aspectj-autoproxy/>
    
    </beans>
    复制代码
    复制代码

    单侧

    复制代码
    复制代码
     // aspectj 注解
        @Test
        public void test011(){
            ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContextspring15.xml");
            ISomeService service = (ISomeService) ctx.getBean("someService");
            service.doSome();
            String aa= service.dade();
            System.out.println(aa);
    
    
        }
    复制代码
  • 相关阅读:
    Zabbix,Nagios,OneAPM Servers 安装部署大比拼
    Android 手把手带你玩转自己定义相机
    Sublime Text3 快捷键
    超具体Windows版本号编译执行React Native官方实例UIExplorer项目(多图慎入)
    poj 1664 放苹果(递推)
    在HyperLedger Fabric中启用CouchDB作为State Database
    HyperLedger Fabric 1.0的Transaction处理流程
    如何将Bitcoin比特币区块链数据导入关系数据库
    在Ubuntu中部署并测试Fabric 1.0 Beta
    在Ubuntu上快速搭建基于Beego的RESTful API
  • 原文地址:https://www.cnblogs.com/wangdan123/p/7284220.html
Copyright © 2011-2022 走看看