aspectj

Aspectj: intercept method from external jar

懵懂的女人 提交于 2019-11-27 16:09:23
问题 I am using a X.jar and adding to my AspectJ project(in eclipse). I have written pointcut and advice for a method myMethod() inside X.jar. But aspectj is not intercepting this method call. How can I tell aspectj to intercept method calls on external jars.Or is it not possible? Thanks 回答1: There are two options: a) compile the aspects into the JAR b) use load time weaving (I'd go with that one) Both of these are advanced topics, I'd suggest you read AspectJ in Action (2nd Ed) by Ramnivas Laddad

aspectj-maven-plugin not covered by lifecycle in Kepler

a 夏天 提交于 2019-11-27 16:08:15
问题 I've just downloaded the OEPE (Kepler) and installed m2e and m2e-wtp connectors. I found out that under this path: Preferences ->Maven->Lifecycle mappings->Open workspace lifecycle mapping data there is a preconfigured xml file which says that maven should ignore the compile goal for AspectJ and I assume that's why the AspectJ runtime libraries are not added to the project hence the project is not recognized as an AspectJ project by eclipse. <?xml version="1.0" encoding="UTF-8"?>

Configuring AspectJ aspects using Spring IoC with JavaConfig?

社会主义新天地 提交于 2019-11-27 16:07:44
According to Spring's Documentation Configuring AspectJ aspects using Spring IoC in order to configure an aspect for Spring IOC, the following has to be added to the xml configuration: <bean id="profiler" class="com.xyz.profiler.Profiler" factory-method="aspectOf"> <property name="profilingStrategy" ref="jamonProfilingStrategy"/> </bean> As suggested by @SotiriosDelimanolis, rewriting this as the following in JavaConfig should to work: @Bean public com.xyz.profiler.Profiler profiler() { com.xyz.profiler.Profiler profiler = com.xyz.profiler.Profiler.aspectOf(); profiler.setProfilingStrategy

关于Spring Aop存在的一点问题的思考

家住魔仙堡 提交于 2019-11-27 15:38:08
在本人前面的文章 Spring Aop原理之切点表达式解析 中讲解了Spring是如何解析切点表达式的,在分析源码的时候,出现了如下将要讲述的问题,我认为是不合理的,后来本人单纯使用aspectj进行试验,发现结果与Spring源码所表现出来的状态是一致的。 1. 现象 我们首先声明一个目标类 Dog ,其方法执行将会被代理,声明如下: public class Dog { public void run() { System.out.println("Tidy is running."); } } 然后是切面类声明如下: @Aspect public class DogAspect { @Around("execution(public void Dog.*(..))") public Object aspect(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println("before run. "); Object result = joinPoint.proceed(); System.out.println("after run."); return result; } } 可以看到,这里 DogAspect 中声明的切面将会环绕 Dog.run() 方法的执行。下面是xml配置和驱动类声明:

How to write an Aspect pointcut based on an annotated parameter

余生颓废 提交于 2019-11-27 15:11:29
问题 I'm having a bit of trouble working out how to create a pointcut that will operate on beans that have a specific annotated parameter. My eventual aim is to validate the value of the parameter before it's processed, but for the moment I just need to create the pointcut. Consider the following annotation @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.PARAMETER }) public @interface MyAnnotation {} I'd then like to apply this to a number of methods like: public void method1(

Aspectj overwrite an argument of a method

青春壹個敷衍的年華 提交于 2019-11-27 14:08:40
I'm developing an aspect that checks arguments of setter methods and overwrites empty strings with null value. This is my state so far: @Before("execution(* de.foo.entity.*.set*(..)) && args(java.lang.String)") public void check(final JoinPoint jp) { LOGGER.debug(jp.getSignature().toLongString()); Object[] args = jp.getArgs(); for (int i = 0; i < args.length; i++) { if (args[i] instanceof String && ((String) args[i]).isEmpty()) { args[i] = null; } } } Unfortunately the overwrite statement args[i] = null; does now work! Do anyone know how should I overwrite it? Cheers, Kevin Ralph I believe you

AspectJ pointcut for annotated PRIVATE methods

杀马特。学长 韩版系。学妹 提交于 2019-11-27 14:03:26
问题 I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method like below. @Aspect public class ServiceValidatorAspect { @Pointcut("within(@com.example.ValidatorMethod *)") public void methodsAnnotatedWithValidated() { } @AfterReturning( pointcut = "methodsAnnotatedWithValidated()", returning = "result") public void throwExceptionIfErrorExists(JoinPoint joinPoint, Object result) { ...

Spring + AspectJ weaving for java 8 using aspectj-maven-plugin

梦想与她 提交于 2019-11-27 12:50:00
I'm migrating my project from java 7 to java 8 and the problem I have is related to aspectj weaving using aspectj-maven-plugin . I could configure successfuly the weaving using this plugin running on Java 6 and 7 according to Haus documentation . But the problem is that I haven't found any way to use (and find) plugin version 7 that supports java 8. I saw here that plugin 7 adds java 8 support but couldn't find a way to use it. This is the configuration plugin I need: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.7</version> <!-- AspectJ

Spring AOP Advice on Annotated Controllers

人走茶凉 提交于 2019-11-27 12:26:39
I am trying to use AOP to do some processing after an annotated controller. Everything is running with no errors, but the advice is not being executed. Here is the controller code: @Controller public class HomeController { @RequestMapping("/home.fo") public String home(ModelMap model) { model = new ModelMap(); return "home"; } } and the setup in application-config <aop:aspectj-autoproxy/> <bean id="testAdvice" class="com.test.TestAdvice"> </bean> <bean id="testAdvisor" class="org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor"> <property name="advice" ref="testAdvice" />

Get annotated parameters inside a pointcut

99封情书 提交于 2019-11-27 11:38:39
问题 I have two annotation @LookAtThisMethod and @LookAtThisParameter , if I have a pointcut around the methods with @LookAtThisMethod how could I extract the parameters of said method which are annotated with @LookAtThisParameter ? For example: @Aspect public class LookAdvisor { @Pointcut("@annotation(lookAtThisMethod)") public void lookAtThisMethodPointcut(LookAtThisMethod lookAtThisMethod){} @Around("lookAtThisMethodPointcut(lookAtThisMethod)") public void lookAtThisMethod(ProceedingJoinPoint