org.springframework.boot
spring-boot-starter-aop
專案結構
@component
public class user
public int addnum(string message, int num)
}
afterreturning是在around後面呼叫,如果同時使用這兩個註解,around需要返回結果,否則afterreturning拿不到返回引數
@component
@aspect
public class aopspringaspect
// 環繞通知
@around("execution(* com.stude.freemarker.aspect.server.user.*(..))")
public object around(proceedingjoinpoint proceedingjoinpoint) throws throwable
@before("within(com.stude.freemarker.aspect.server.*)")
public void before(joinpoint joinpoint)
@afterreturning(value = "within(com.stude.freemarker.aspect.server.*)",returning = "rvt")
public void after(joinpoint joinpoint,object rvt)
}
@enableasync
public static void main(string args)
}
/**
* created on 2019/4/6.
* * @author grak
* @since 1.0
*/@component
public class transactionutils
// 提交事務
public void commit(transactionstatus transactionstatus)
// 回滾事務
public void rollback(transactionstatus transactionstatus)
}
/**
* created on 2019/4/6.
* * @author grak
* @since 1.0
*/@component
@aspect
public class aopspringaspect
// 環繞通知
@around("execution(* com.stude.aop.aspect.jdbcaspect.demoaspect.runaspect(..))")
public void around(proceedingjoinpoint proceedingjoinpoint) throws throwable
}
/**
* created on 2019/4/5.
* * @author grak
* @since 1.0
*/@component
public class user
public void addnum(string message, int num)
}
public static void main(string args) } Spring註解使用(基於Aspect)
引入xmln context命名空間 package com.xzj.advice context component scan component 該註解相當於 如果沒有引數,把類首字母變小寫,相當於 component 自定義名稱 在spring配置檔案中設定註解在哪些包 base packag...
Spring Anno AOP 基於註解的AOP)
參考文章 aspect註解 package com.itheima.utils import org.aspectj.lang.proceedingjoinpoint import org.aspectj.lang.annotation.import org.springframework.ster...
使用註解實現IoC AOP
什麼是註解?用來修飾 表示一些額外的資訊。源註解 修飾註解的註解。定義註解 inte ce spring提供的註解 1 ioc操作 1 component 用於實現ioc控制反轉,屬性value用於實現物件id定義 2 scope 用於實現單例,多例,request,session等的配置 3 co...