SpringBoot?AOP?@Pointcut切入點表達式排除某些類方式
SpringBoot AOP @Pointcut切入點表達式排除某些類
場景
希望給service包下的所有public方法添加開始和結(jié)束的info log,但是需要排除和數(shù)據(jù)庫相關(guān)的service
其他博文都推薦了
@Pointcut("execution(* com.demo.service.*.*(..)) && !execution(* com.demo.service.dbservice.*(..)) ")
類似的用法,但是在實際操作中,發(fā)現(xiàn)&&這個關(guān)鍵字無法使用,只能使用and才能編譯通過,并且@Pointcut只識別了前面半句表達式,and(&&)之后的內(nèi)容被無視了。
使用以下方法滿足了開發(fā)需求
@Pointcut("execution(public * com.demo.service.*.*(..))")
public void serviceMethods() {
}
@Pointcut("execution(public * com.demo.service.dbservice.*(..))")
public void serviceMethods2() {
}
@Pointcut("serviceMethods() && !serviceMethods2()")
public void serviceMethods3() {
}
@Before("serviceMethods3()")
public void startLog(JoinPoint joinPoint) {
String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
String methodName = joinPoint.getSignature().getName();
logger.info("{}.{} start", className, methodName);
}
AOP排除某些類型不攔截
/**
* 日志記錄切面
*/
@Aspect
public class Logger implements ILogger {
@Resource(name="logService")
private LogService logService ;
@Pointcut("execution(* *..*Action*.*(..)) && !execution(* com.audaque.tjfxpt.web.sjcx.LogAction.*(..))")
public void actionPointCut() {
}
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
- SpringBoot中使用?POI的示例代碼
- SpringBoot EasyPoi動態(tài)導(dǎo)入導(dǎo)出的兩種方式實現(xiàn)方法詳解
- SpringBoot如何基于POI-tl和word模板導(dǎo)出龐大的Word文件
- SpringBoot集成POI實現(xiàn)Excel導(dǎo)入導(dǎo)出的示例詳解
- springboot?aop里的@Pointcut()的配置方式
- springboot中EasyPoi實現(xiàn)自動新增序號的方法
- 淺談springboot之JoinPoint的getSignature方法
- SpringBoot中使用JeecgBoot的Autopoi導(dǎo)出Excel的方法步驟
- springboot中poi使用操作方法
相關(guān)文章
SpringBoot整合token實現(xiàn)登錄認(rèn)證的示例代碼
本文主要介紹了SpringBoot整合token實現(xiàn)登錄認(rèn)證的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
SpringBoot發(fā)送異步郵件流程與實現(xiàn)詳解
這篇文章主要介紹了SpringBoot發(fā)送異步郵件流程與實現(xiàn)詳解,Servlet階段郵件發(fā)送非常的復(fù)雜,如果現(xiàn)代化的Java開發(fā)是那個樣子該有多糟糕,現(xiàn)在SpringBoot中集成好了郵件發(fā)送的東西,而且操作十分簡單容易上手,需要的朋友可以參考下2024-01-01
MyBatis Map結(jié)果的Key轉(zhuǎn)為駝峰式
今天小編就為大家分享一篇關(guān)于MyBatis Map結(jié)果的Key轉(zhuǎn)為駝峰式,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12
springboot 同時啟用http/https的配置方法
本文給大家分享springboot 同時啟用http/https的配置方法,通過修改配置文件、增加java配置的方法來實現(xiàn)此操作,具體內(nèi)容詳情跟隨小編通過本文學(xué)習(xí)下吧2021-05-05

