方面日志记录:与此类型名称不匹配,我做错了什么?
Aspect Logging: no match for this type name, what am I doing wrong?
这是我的日志记录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;
}
}
}
这是我遇到的例外情况
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]
这是我的结构。我的控制器 classes 在这个目录下,为什么不匹配?
非常感谢您的帮助!
你有一些基本的语言类型错误
within(@com.topjava.graduation.restaurant *)
检查这个和你拥有的另一个 within(@...)
当你想为 类 表示带有以下注释时,你应该使用 @
。例如,您将使用 within(@org.springframework.stereotype.Repository *)
并且您的意思是 类 具有来自 Spring.
的注释 @Repository
在您的情况下,您指的是包裹。那么正确的做法是 within(com.topjava.graduation.restaurant.*)
所以最后一定要更正为
@Pointcut("within(com.topjava.graduation.restaurant.*)" +
" || within(com.topjava.graduation.restaurant.service.*)" +
" || within(com.topjava.graduation.restaurant.controller.*)")
这是我的日志记录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;
}
}
}
这是我遇到的例外情况
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]
这是我的结构。我的控制器 classes 在这个目录下,为什么不匹配?
非常感谢您的帮助!
你有一些基本的语言类型错误
within(@com.topjava.graduation.restaurant *)
检查这个和你拥有的另一个 within(@...)
当你想为 类 表示带有以下注释时,你应该使用 @
。例如,您将使用 within(@org.springframework.stereotype.Repository *)
并且您的意思是 类 具有来自 Spring.
@Repository
在您的情况下,您指的是包裹。那么正确的做法是 within(com.topjava.graduation.restaurant.*)
所以最后一定要更正为
@Pointcut("within(com.topjava.graduation.restaurant.*)" +
" || within(com.topjava.graduation.restaurant.service.*)" +
" || within(com.topjava.graduation.restaurant.controller.*)")