【发布时间】:2021-09-03 20:01:00
【问题描述】:
这是我的日志类
@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;
}
}
}
这是我的例外
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]
非常感谢您的帮助!
【问题讨论】:
标签: java spring spring-boot aop