簡體   English   中英

在Spring AOP中@Around沒有被調用

[英]@Around not getting called in Spring AOP

我試圖在Spring中記錄使用AOP的方法。 我僅使用System.out.println()嘗試了以下代碼,但未得到調用。

創建的注釋:

   @Retention(value = RetentionPolicy.RUNTIME)  
   @Target(value = ElementType.METHOD)  
   public @interface Loggable {
   }

創建的方面

  @Aspect
  public class MethodLogger  {

     @Around("execution(* *(..)) && @annotation(Loggable)")
     public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("this is called");
        return result;
     }
  }

服務層中使用過的登錄方法

   @Service("RegionService")
   @Transactional(readOnly = false)
   public class RegionService implements IRegionService{
   @Loggable
   @Override
   public List<> fetch() {      
      return dao.xyz();
   }
   }

彈簧配置

    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
    >
    <context:component-scan base-package="com.sst.tender.spring"/>
<context:annotation-config/>
<context:spring-configured/>
 </beans>

@Component添加到MethodLogger類。 另外,您還必須像以下方法之一一樣啟用AspectJ:

  • @EnableAspectJAutoProxy添加到配置Bean類。 (注釋驅動的方法)
  • <aop:aspectj-autoproxy />到應用程序上下文文件中。 (XML驅動的方法)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM