zoukankan      html  css  js  c++  java
  • Aspectj 注解

    1.aspectj 注解

    public interface ISomeService {
        public void doSome();
    
        public String doSecont();
    }
    public class SomeService implements ISomeService {
        //核心业务
        public void doSome() {
            System.out.println("拜托别让他一番努力换来是奢求!");
        }
    
        public String doSecont() {
            System.out.println("++===================Secont 天天新网友====================++");
            return "doSecont";
        }
    
    
    }
    public class MySecont {
    
        //前置增强
        @Before(value = "execution(* *..spring12aop_note.*.*(..))")
        public void myBefore(){
            System.out.println("===我是前置增强内容======");
        }
        //后置增强
        //@AfterReturning(value = "execution(* *..spring12aop_note.*.*(..))")
        public void myAferReturing(){
            System.out.println("===我是after后置增强内容======");
        }
    
        //环绕增强
        //@Around(value = "execution(* *..spring12aop_note.*.*(..))")
        public Object myAround(ProceedingJoinPoint proceed) throws Throwable {
            System.out.println("===我是环绕前内容======");
            Object result = proceed.proceed();
            System.out.println("===我是环绕后内容======");
            if (result!=null){
                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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
           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">
    
        <!--aspectj 注解-->
    
        <!--01.目标对象-->
        <bean id="someService" class="cn.happy.spring12aop_note.SomeService"></bean>
    
        <!--02.增强 通知-->
        <bean id="beforeAdvice" class="cn.happy.spring12aop_note.MySecont"></bean>
    
        <aop:aspectj-autoproxy/>
    
    
    
    </beans>

    单测

    //1.aspectj 注解
        @Test
        public void test05(){
            ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext09_aop09_note.xml");
            ISomeService service = (ISomeService) ctx.getBean("someService");
            service.doSome();
            service.doSecont();
        }
  • 相关阅读:
    idea 类路径跳转问题?
    关于Guava中I/O中Files类各个方法的解读
    ELASTICSEARCH-分析器详解和搜索原理
    字符串正则替换
    使用jacob调用Windows的com对象,进行word、ppt等转换成ptf、html(二)
    使用jacob调用Windows的com对象,进行word、ppt等转换成ptf、html
    mongodb常用查询语法
    idea git 版本回滚
    ElasticSearch系列
    SpringBoot集成Elasticsearch 进阶,实现中文、拼音分词,繁简体转换高级搜索
  • 原文地址:https://www.cnblogs.com/shiwz/p/7267945.html
Copyright © 2011-2022 走看看