aspectj

AspectJ: How to get accessed field's value in a get() pointcut

↘锁芯ラ 提交于 2019-12-21 19:53:09
问题 I am writing an aspect logger to write a log whenever any member variable in a given class is accessed. If I write a specific pointcut for a single variable like below, I am able to get the value of the field. @Pointcut("get(* abc.ThreadPoolService.drMaxTh)") public void drFields() {} @AfterReturning(pointcut="drFields()", returning="drMaxTh") public void afterAccessingdrFields(int drMaxTh) { LOGGER.info("Accessed the field drMaxTh " + drMaxTh); } But my class has a dozen+ variables, and I

How does AspectJ's load-time-weaver find META-INF\aop.xml?

点点圈 提交于 2019-12-21 17:50:07
问题 I am attempting to use load-time-weaving to tie perf4j into a program, but it does not seem to be finding aop.xml in my classpath. Either that or it is not weaving the aspect because it is not finding it. I have enabled verbose output from aop.xml but I am not seeing any weaving messages, errors or otherwise. Where does aspectJweaver look for the META-INF/aop.xml? How can I tell which one it is looking for? I have attempted to use a direct path to import the xml with this, but it hasn't

AspectJ Inner-Class Join points

家住魔仙堡 提交于 2019-12-21 17:40:33
问题 I wonder is there a way to reach the code using aspect in "//do something" part? Thanks in advance. Turan. public class Test { private class InnerTest { public InnerTest() { JButton j = new JButton("button"); j.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //do something } }); } } } 回答1: You can use the within or withincode pointcuts to match the containing class, and the cflow pointcut to match the execution of the addActionListener() method, then

Pointcut for methods with @Scheduled Spring annotation

心不动则不痛 提交于 2019-12-21 14:34:37
问题 I want to have a AspectJ pointcut for methods annotated with @Scheduled . Tried different approaches but nothing worked. 1.) @Pointcut("execution(@org.springframework.scheduling.annotation.Scheduled * * (..))") public void scheduledJobs() {} @Around("scheduledJobs()") public Object profileScheduledJobs(ProceedingJoinPoint joinPoint) throws Throwable { LOG.info("testing") } 2.) @Pointcut("within(@org.springframework.scheduling.annotation.Scheduled *)") public void scheduledJobs() {} @Pointcut(

Why my Aspect is not detected for Jersey controller (using custom annotation)?

删除回忆录丶 提交于 2019-12-21 12:32:54
问题 I want to create an Aspect over a Jersey controller to measure how long the services take to be executed. I'm fighting against my pointcut since it isn't detected and my aspect never gets launched. I have tried using lots of pointcuts like: execution(@Monitor * *.*(..)) execution(public * *(..)) change the order of @Aspect and @Component Added a pointcut like this: @Pointcut("execution(@Monitor * *.*(..))") public void monitorRequestTargets(){} @Around("monitorRequestTargets()") Tried using

spring aop

狂风中的少年 提交于 2019-12-21 11:08:34
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 通知类型 package com.aspectj; import org.apache.log4j.Logger; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; @Component @Aspect //该类是一个切面 public class MyAspectJ { Logger logger = Logger.getLogger(MyAspectJ.class); // 切入点: 假设我这个切入点指定的是 service包下面的所有的方法 // 第一个宽字符 * 匹配 任何返回类型,第二个宽字符 * 匹配 任何方法名,最后的参数 (..) 表达式匹配任意数量任意类型的参数,也就是说该切点会匹配类中所有方法的调用。 @Pointcut("execution(* com.service.*..* (..))") public void qrd(){} // 前置增强, 要给目标方法织入什么的业务 @Before("qrd()")

How to swallow a exception at AfterThrowing in AspectJ

纵然是瞬间 提交于 2019-12-21 09:35:00
问题 In AspectJ, I want to swallow a exception. @Aspect public class TestAspect { @Pointcut("execution(public * *Throwable(..))") void throwableMethod() {} @AfterThrowing(pointcut = "throwableMethod()", throwing = "e") public void swallowThrowable(Throwable e) throws Exception { logger.debug(e.toString()); } } public class TestClass { public void testThrowable() { throw new Exception(); } } Above, it didn't swallow exception. The testThrowable()'s caller still received the exception. I want caller

Why do I get a not exposed to the weaver warnings when making my Spring project?

。_饼干妹妹 提交于 2019-12-21 08:17:11
问题 I seem to get a bunch of warnings like this when I make my Spring project. The project uses Compile Time Weaving and various Spring annotations like Transactional, Autowired, and Configurable. I have three questions: What are they (What's the effect)? Should I be concerned about them? and "What can I do to remove them?" ajc: this affected type is not exposed to the weaver: com.myapp.domain.UserEntity [Xlint:typeNotExposedToWeaver] Let me know what you need to help me solve this issue. I can

Pass method argument in Aspect of custom annotation

醉酒当歌 提交于 2019-12-21 07:59:06
问题 I'm trying to use something similar to org.springframework.cache.annotation.Cacheable : Custom annotation: @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface CheckEntity { String message() default "Check entity msg"; String key() default ""; } Aspect: @Component @Aspect public class CheckEntityAspect { @Before("execution(* *.*(..)) && @annotation(checkEntity)") public void checkEntity(JoinPoint joinPoint, CheckEntitty checkEntity) { System.out

Getting a return value or exception from AspectJ?

半城伤御伤魂 提交于 2019-12-21 07:07:54
问题 I am able to get the signature and arguments from advised method calls, but I cannot figure out how to get the return values or exceptions. I'm kind of assuming that it can be done in some way using around and proceed. 回答1: You can use after() returning and after() throwing advices as in beginning of the following document. If you're using @AspectJ syntax please refer to @AfterReturning and @AfterThrowing annotations (you can find samples here). 回答2: You can also get return value using after