Skip to content
Advertisement

Aspect Logging: no match for this type name, what am I doing wrong?

Here is my Logging class

@Aspect
@Component
public class LoggingAspect {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Pointcut("within(@com.topjava.graduation.restaurant *)" +
            " || within(@com.topjava.graduation.restaurant.service *)" +
            " || within(@com.topjava.graduation.restaurant.controller *)")
    public void springBeanPointcut() {
        // Method is empty as this is just a Pointcut, the implementations are in the advices.
    }

//      Advice that logs methods throwing exceptions.
    @AfterThrowing(pointcut = "springBeanPointcut()", throwing = "e")
    public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
        log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause() != null ? e.getCause() : "NULL");
    }

//      Advice that logs when a method is entered and exited.

    @Around("springBeanPointcut()")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        if (log.isDebugEnabled()) {
            log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
        }
        try {
            Object result = joinPoint.proceed();
            if (log.isDebugEnabled()) {
                log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                        joinPoint.getSignature().getName(), result);
            }
            return result;
        } catch (IllegalArgumentException e) {
            log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                    joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
            throw e;
        }
    }
}

Here is the exception I have

 Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: com.topjava.graduation.restaurant [Xlint:invalidAbsoluteTypeName]

Here is the structure I have. I have my controller classes under this dir, why is there no match? Controller Structure

I do appreciate your help a lot!

Advertisement

Answer

You have some basically language type error

within(@com.topjava.graduation.restaurant *)

check this and the other within(@...) that you have

You should use @ when you want to mean for classes that bring the following annotation. For example you would use within(@org.springframework.stereotype.Repository *) and you would mean classes that have the annotation @Repository from Spring.

In your case you intend to mean the package. Then the correct way of doing that is within(com.topjava.graduation.restaurant.*)

So in the end you must correct it to

  @Pointcut("within(com.topjava.graduation.restaurant.*)" +
                " || within(com.topjava.graduation.restaurant.service.*)" +
                " || within(com.topjava.graduation.restaurant.controller.*)")

Advertisement