AspectJ - аспект выполняется выполняется 2 раза

Проблема в следующем. Аспект выполняется не только в том методе, который в pointcut попадает, но также - он еще раз выполняется и в том методе, который указанный в pointcut метод вызвал. Т.е. к примеру есть метод:

        public class Handler {
    
        @LogServiceCall
        public ReturnType handle(ArgType message) {
          ReturnType response;
          //do something
          return response;
       }
    }

Есть класс, из которого этот метод вызывается:

    public class Caller {

      @Autowired
      private Handler requestHandler;

      public ReturnType getResponse(ArgType message) {
        return requestHandler.handle(message);
    }
}

При вызове метода getResponse в Caller - аспект вызывается дважды - сначала в методе handle, а затем еще раз - в методе getResponse.

Код аспекта:

@Aspect
public class LoggingAspect {

    @Autowired
    private ContextLoggerService loggerService;

    @Autowired
    private RequestContextHolderService contextHolder;

    @Around("@annotation(logServiceCall)")
    public Object logServiceCall(ProceedingJoinPoint serviceJoinPoint, LogServiceCall logServiceCall) throws Throwable {
        //do logging before method call
        Object response = serviceJoinPoint.proceed();
        //do logging after method call>
        return response;
    }
}

Аннотация:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogServiceCall {

    ServiceProfile serviceName() default ServiceProfile.NO_SUCH_SERVICE;
}

Конфигурация контекста Spring:

<aop:aspectj-autoproxy/>
<bean id="loggingAspect" class="logging.aspect.LoggingAspect"
      factory-method="aspectOf"/>

Также на всякий случай привожу конфигурацию mavan-aspectj-plugin:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.11</version>
    <configuration>
        <complianceLevel>8</complianceLevel>
        <source>8</source>
        <target>8</target>
        <showWeaveInfo>true</showWeaveInfo>
        <verbose>true</verbose>
        <Xlint>ignore</Xlint>
        <encoding>UTF-8</encoding>
        <excludes>
            <exclude>**/*.java</exclude>
        </excludes>
        <forceAjcCompile>true</forceAjcCompile>
        <sources/>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>
    <executions>
        <execution>
            <id>default-compile</id>
            <phase>process-classes</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <weaveDirectories>
                    <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
                </weaveDirectories>
            </configuration>
        </execution>
        <execution>
            <id>default-testCompile</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>test-compile</goal>
            </goals>
            <configuration>
                <weaveDirectories>
                    <weaveDirectory>${project.build.directory}/test-classes</weaveDirectory>
                </weaveDirectories>
            </configuration>
        </execution>
    </executions>
</plugin>

Ответы (0 шт):