일반적인 주석을 사용하여 Aspect를 만들려고했습니다.
@Aspect
@Component
public class CommonAspect<T extends CommonEntity>{
@AfterReturning(value = "@annotation(audit)",returning="retVal")
public void save(JoinPoint jp,T retVal, Audit audit) {
Audit audit = new Audit();
audit.setMessage(retVal.getAuditMessage());
//other code to store audit
}
}
이것이 가능한가 ? 제 경우에는 실패합니다. 이 @Audit 주석을 사람, 사용자 등 다른 종류의 엔티티에 사용하고 싶습니다. 따라서 반환 값은 일반적 일 수 있습니다.
을 반환하는 메서드에 대한 측면을 정의하려는 것 같습니다 CommonEntity
. 이 경우 제네릭을 사용할 필요가 없습니다. 제네릭 선언을 제거하고 aspect 선언을 약간 조정할 수 있습니다.
@Aspect
@Component
public class CommonAspect {
@AfterReturning(value = "@annotation(audit) && execution(CommonEntity *(..))",returning="retVal")
public void save(JoinPoint jp, CommonEntity retVal, Audit audit) {
Audit auditInfo = new Audit();
auditInfo.setMessage(retVal.getAuditMessage());
//other code to store audit
}
}
내가 한 일은 T
인수 목록에서를 바꾸고 execution(CommonEntity *(..))
pointcut 표현식에 추가 하여 a CommonEntity
가 반환 되는 pointcut에 대한 일치를 제한하는 것 입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다