Spring學習筆記三 註解AOP

2021-09-17 19:49:41 字數 950 閱讀 1783

1.匯入jar包
@service

public class studentservice

}

<?xml version="1.0" encoding="utf-8"?>			

@component

@aspect

public class studentadvice

@afterreturning(value="execution(* cn.wang.service..*(..))")

//如果目標方法有返回值,後置增強不管配部配returning 都會執行

// 環繞增強必須接受返回值

//如果目標方法沒有返回值,後置增強配置了returning 則 後置增強不會執行

public void after(joinpoint joinpoint)

@after(value="execution(* cn.wang.service..*(..))")

public void finalafter()

@afterthrowing(value="execution(* cn.wang.service..*(..))",throwing="e")

public void throwadvice(joinpoint joinpoint,exception e)

@around(value="execution(* cn.wang.service..*(..))")

public object around(proceedingjoinpoint joinpoint) throws throwable

}

public class teststudent 

}

spring之基於aspectj註解aop使用

在配置檔案中開啟aop自動 1 在增強類上面使用 aspect註解 2 在增強方法上面配置不同型別通知 增強類 aspect public class myuser 後置通知 afterreturning value execution cn.aop.user.update public void ...

Spring 學習筆記(三)之註解

一.在classpath下掃瞄元件 元件掃瞄 component scanning spring 能夠從 classpath 下自動掃瞄,偵測和例項化具有特定註解的元件.特定元件包括 component 基本註解,標識了乙個受 spring 管理的元件 respository 標識持久層元件 ser...

Spring 註解學習筆記

宣告bean的註解 注入bean的註解 配置檔案的註解 aop切面程式設計註解 spring 常用配置 postconstruct 在建構函式執行完之後執行 predestroy 在 bean 銷毀之前執行 activeprofiles 用來宣告活動的 profile profile 為不同環境下使...