第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 AspectJ 的日志控制器

使用 AspectJ 的日志控制器

皈依舞 2022-11-02 15:56:53
我有一個 Spring Boot 應(yīng)用程序,我想記錄一些信息,當(dāng)調(diào)用 Controller 方法 id 時會發(fā)生什么。出于某種原因,我的 Aspect 無法正常工作。這是我用@Aspect 注釋的@Component 類:@Pointcut("within(@org.springframework.stereotype.Controller *)")public void controller() {}@Pointcut("execution(* *.*(..))")protected void allMethod() {}@Before("controller()&& allMethod()")public void logBefore(JoinPoint joinPoint) {}當(dāng)使用 REST 調(diào)用任何 Controller 方法時,不會調(diào)用 logBefore 方法。
查看完整描述

2 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個贊

重要提示:正如您所說,您使用的是 Spring Boot 設(shè)置,我的假設(shè)是您已經(jīng)實(shí)現(xiàn)了 Spring AOP 模塊而不是“實(shí)際的”AspectJ 庫。差異是顯著的,因?yàn)?AOP 的實(shí)現(xiàn)在它們之間有所不同。Spring 使用 AspectJ 注釋來應(yīng)用代理,而 AspectJ 將代碼“編織”到您的應(yīng)用程序中。簡而言之,Spring AOP 可能更容易實(shí)現(xiàn),而 AspectJ 提供了更細(xì)粒度的功能(例如編譯時編織)。可以在這里找到比較。


我已經(jīng)從您在帖子中提供的代碼片段中嘗試了配置。在我添加了幾個注釋后調(diào)用了該建議:


@SpringBootApplication

// Be sure to add EnableAspectJAutoProxy and set proxyTargetClass to true

@EnableAspectJAutoProxy(proxyTargetClass = true)

public class DemoApplication {

  ...

}

// Be sure to add @Aspect and @Component

@Component

@Aspect

public class DemoAop {


  private static Logger logger = LoggerFactory.getLogger(DemoAop.class);


  @Pointcut("within(@org.springframework.stereotype.Controller *)")

  public void controller() {

  }


  @Pointcut("execution(* *.*(..))")

  protected void allMethod() {

  }


  @Before("controller()&& allMethod()")

  public void logBefore(JoinPoint joinPoint) {

    logger.info("TEST");

  }


}


查看完整回答
反對 回復(fù) 2022-11-02
?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個贊

在運(yùn)行時,您的控制器使用 @RestController 而不是 @Controller 進(jìn)行注釋。

只需將切入點(diǎn)更改為 RestController 即可:

 @Pointcut("within(@org.springframework.web.bind.annotation.RestController *)")
 public void controller() {
 }


查看完整回答
反對 回復(fù) 2022-11-02
  • 2 回答
  • 0 關(guān)注
  • 138 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號