java - Aspect 仅适用于 Aspect 类所在包上的类
问题描述
我正在尝试使用 AOP 记录方法的进入/退出。但是我只能记录作为 Aspect 类所在包的一部分的方法的进入/退出。我无法记录其他包中的方法.请帮助。提前致谢。
这是我的代码:
@Component
@Aspect
public class MyAspect {
@Before("execution(* com.dave.school.student..*(..))")
public void before(JoinPoint joinPoint)
{
System.out.println("Before::");
System.out.println(joinPoint.getSignature().getDeclaringTypeName() + "/" + joinPoint.getSignature().getName());
System.out.println(Arrays.toString(joinPoint.getArgs()));
}
@Before("execution(* com.dave.school.teachers..*(..))")
public void before1(JoinPoint joinPoint) //doesn't work
{
System.out.println("Before::");
System.out.println(joinPoint.getSignature().getDeclaringTypeName() + "/" + joinPoint.getSignature().getName());
System.out.println(Arrays.toString(joinPoint.getArgs()));
}
@AfterReturning(pointcut ="execution(* com.dave.school.student..*(..))",returning = "result")
public void after(JoinPoint joinPoint,Object result) throws JsonProcessingException {
System.out.println("After::");
System.out.println(joinPoint.getSignature().getDeclaringType().getName());
ObjectMapper objectMapper=new ObjectMapper();
String r=objectMapper.writeValueAsString(result);
System.out.println("Result is ::" + r );
}
}
这是我的春季启动应用程序:
@SpringBootApplication(scanBasePackages = {"com.dave.school"})
@EnableJpaRepositories(basePackages = {"com.dave.school"})
@EntityScan(basePackages = {"com.dave.school"})
@ComponentScan(basePackages = {"com.dave.school"})
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}
解决方案
推荐阅读
- filter - ffmpeg filter dev get_video_buffer 函数用法
- javascript - HTML 表单自动填充
- python - 我可以在 python raw_input 函数的提示符中使用变量吗?
- c# - 如何从 SQliteConnection c# Xamarin Android 中列出表名
- python - Django-allauth 将注册限制为电子邮件列表
- python - 如何在python中从未来检索任务?
- macos - 导出 PDF:找不到字体
- c++ - 为什么 i = ++i + 2 是未定义的行为?
- python - 3种python库中的MFCC和delta系数
- tensorflow - Sagemaker ImportError:不支持按文件名导入