@Component public class UserService {
// 业务逻辑代码
}
@Service public class UserService {
@Autowired
private UserRepository userRepository;
// 业务方法
}
@Aspect @Component public class LoggingAspect {
@Before("execution(* com.example.service.*.*(..))")
public void logMethodCall(JoinPoint joinPoint) {
System.out.println("调用方法: " + joinPoint.getSignature().getName());
}
@AfterReturning(pointcut = "execution(* com.example.service.*.*(..))", returning = "result")
public void logMethodResult(JoinPoint joinPoint, Object result) {
System.out.println("方法返回: " + result);
}
}

你可能想看: