// aspect-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean name="referenceAspect"
class="com.example.reference.audit.aspect.ReferenceAuditAspect"></bean>
<bean name="mainApplicationTypeAspect"
class="com.example.maintenance.audit.aspect.MaintApplicationTypeAuditAspect"></bean>
<aop:aspectj-autoproxy proxy-target-class="true" />
<aop:config>
<aop:aspect ref="referenceAspect">
<!-- @around sysad log annotation -->
<aop:pointcut id="referencePointCut" expression="@annotation(etisLog)" />
<aop:around method="auditLogAround" pointcut-ref="referencePointCut" />
</aop:aspect>
<aop:aspect ref="mainApplicationTypeAspect">
<!-- @around sysad log annotation -->
<aop:pointcut id="mainApplicationTypePointCut" expression="@annotation(etisLog)" />
<aop:around method="auditLogAround" pointcut-ref="mainApplicationTypePointCut" />
</aop:aspect>
</aop:config>
</beans>
У меня есть два класса аспектов:
@Component
public class ReferenceAuditAspect {
public Object auditLogAround(ProceedingJoinPoint joinPoint, ETISLog etisLog)
throws Throwable {
LOGGER.info("INTERCEPTING REFERENCE SERVICE...");
}
}
@Component
public class MaintApplicationTypeAuditAspect {
public Object auditLogAround(ProceedingJoinPoint joinPoint, ETISLog etisLog)
throws Throwable {
LOGGER.info("INTERCEPTING REFERENCE SERVICE...");
}
}
// Мое выражение pointcut
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ETISLog {
}
//Перехват на уровне API
@ETISLog
public ResponseEntity<MaintApplicationType> save(
@RequestBody MaintApplicationType maintApplicationType) {
LOGGER.info("API: SAVE {}", maintApplicationType);
return new ResponseEntity<>(maintApplicationTypeService.save(maintApplicationType),
HttpStatus.CREATED);
}
Но почему, когда я запускаю свое приложение и выполняю операцию сохранения в maintApplicationApi, всегда выполняется аспект ReferenceAuditAspect вместо mainApplicationTypeAspect.У меня есть код внутри AuditLogAround, который выполняет определенные операции.
Я следовал документации здесь: https://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/aop.html -> 8.3 Раздел
Я также пытался удалить: <aop:aspectj-autoproxy proxy-target-class="true" />
, но та же проблема