У меня типичная задача проверить время выполнения многих функций.Я сделал аннотацию
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ProceedTimeLogger {}
и аспект этой аннотации
@Aspect
@Component
public class ProceedTimeLoggerAspect {
public static final Logger LOGGER = LoggerFactory.getLogger(ProceedTimeLoggerAspect.class);
@Around(value = "(@within(com.security.annotation.ProceedTimeLogger) " +
"|| @annotation(com.security.annotation.ProceedTimeLogger))" +
"|| execution(* com.security.permissions.permissions.*+.*(..))")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
String methodName = pjp.getSignature().getName();
String methodId = getMethodId();
long start = System.currentTimeMillis();
LOGGER.info("method '{}' id={} started", methodName, methodId);
Object proceed = pjp.proceed();
long end = System.currentTimeMillis() - start;
LOGGER.info("method '{}' id={} proceed time = {} ms", methodName, methodId, end);
return proceed;
}
public String getMethodId() {
String randomUUID = UUID.randomUUID().toString();
return randomUUID.substring(randomUUID.lastIndexOf("-") + 1, randomUUID.length());
}
}
Теперь моя аннотация охватывает около 40 сомов, но из всех этих классов она работает только в одном методе:
@Component
@ProceedTimeLogger
public class Permission {
...some methods...
//this function covers!!
public PermissionDTO getDTO(String permissionVal, String productDictId) {
PermissionDTO result = new PermissionDTO();
result.setMenuView(isMenuView(productDictId));
result.setDataView(isDataView(productDictId));
result = initOptionalDtoFields(result, productDictId);
return result;
}
...another non-covered methods...
public String getProductType(String productDictId) {
if (productDictId == null) {
return null;
}
Product product = dataDispatcher.getDictionaryById(Product.class, Long.valueOf(productDictId));
return Optional.ofNullable(product.getType())
.map(BaseDict::getIdMDMP)
.map(String::valueOf)
.orElse(null);
}
@ProceedTimeLogger
public String getProductCategory(String productDictId) {
if (productDictId == null) {
return null;
}
Product product = dataDispatcher.getDictionaryById(Product.class, Long.valueOf(productDictId));
return Optional.ofNullable(product.getProductCategory())
.map(BaseDict::getIdMDMP)
.map(String::valueOf)
.orElse(null);
}
}
Чем отличается?Почему эти методы не охватываются?