Questions tagged [aspectj]

AspectJ is an aspect-oriented extension to the Java programming language that enables clean modularization of crosscutting concerns such as logging, error handling, standards enforcement and feature variations. Use this tag for questions about the programmatic use of this extension. For downloads, support, IDE integration, & documentation, see the "learn more" for this tag.

AspectJ is an Aspect-Oriented Programming (AOP) extension to Java, created by Xerox, that has as main components aspects (consisting of pointcuts and advices) and join points.

For AspectJ Eclipse integration, also see AspectJ Development Tools (AJDT); for NetBeans integration, see AspectJ in NetBeans; for IntelliJ IDEA integration, see IDEA Web Help.

Books:

Documentation:

3304 questions
9
votes
2 answers

How do I pass arguments to Spring AOP advice with annotated parameters?

I am using Spring 3.1.2.RELEASE with cglib load-time weaving and I am trying to get advice to work with a method that has custom annotations and annotated parameters. Advice: @Aspect public class MyAdvice { …
Brad
  • 2,261
  • 3
  • 22
  • 32
9
votes
1 answer

AspectJ & Maven warning: "Advice defined in ... has not been applied?"

I'm trying to weave some aspects at compile time into a project that becomes a WAR. The aspects advise classes that are within the same project (though in different packages). I get the warning: Advice not applied My aspect is not being executed. …
PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56
9
votes
1 answer

AspectJ - Get value of annotated method parameter

I created custom annotation @MyAnn. And I will annotate method parameters with it. For example: public static call(@MyAnn String name){...} Using AspectJ, how can I access and update the values of all parameters annotated with the annotation? I…
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
9
votes
1 answer

Weaving in toString() implementation with AspectJ

Trying to weave in a default toString() method for a large number of DTOs, using compile-time weaving only. The goal is to return a JSON representation using the Jackson library. Followed the suggestions in this article, turned it into…
raulk
  • 2,809
  • 15
  • 32
9
votes
1 answer

Set an AspectJ advise for static method

I have written simple Aspect with primitive Pointcut and Advise method: @Aspect public class MyAspect { @Pointcut("execution(static * com.mtag.util.SomeUtil.someMethod(..))") public void someMethodInvoke() { } @AfterReturning(value =…
izhamoidsin
  • 133
  • 1
  • 1
  • 4
9
votes
2 answers

How to get the method name that thrown the exception in Java

I have an aspect that runs after an exception is thrown from my TestNG test method. I would like to get the Test method name into my aspectj method. Any thoughts on this? Please find my code sample below: Aspect: pointcut publicCall(): call(public…
rookie007r
  • 93
  • 1
  • 4
9
votes
1 answer

How do you configure aspectj maven plugin to use Java 7?

What are the appropriate configuration/versions/plugin versions for the aspectj plugin to use Java 7? I am trying to upgrade from Java 6 to Java 7, and the aspectj compiler seems to not be compiling Java 7. I'm specifying the java source and target…
Jason
  • 7,356
  • 4
  • 41
  • 48
9
votes
3 answers

Disable/Avoid an advice execution in AspectJ

Suppose I have an aspect public aspect Hack { pointcut authHack(String user, String pass): call(* Authenticator.authenticate(String,String)) && args(user,pass); boolean around(String user, String pass): authHack(user,pass) { out("$$$ " + user…
emesx
  • 12,555
  • 10
  • 58
  • 91
9
votes
2 answers

How to configure load-time weaving with AspectJ and Tomcat?

I tried to configure load-time weaving (for doing profiling with Perf4J) in the next way: 1) I added aop.xml to META-INF folder. When deployed, META-INF is placed in the artifact root directory (i.e. MyAppDeployed/META-INF). 2) I put…
Roman
  • 64,384
  • 92
  • 238
  • 332
8
votes
1 answer

Aspectj aspect for specifying multiple packages

I wanted to specify a pattern for aspectj @Around aspect that includes multiple packages. Example : package 1 : aaa.bbb.ccc.ddd package 2 : aaa.bbb.ccc.eee package 3 : aaa.bbb.ccc.eee.fff Pattern which i used :…
crankparty
  • 1,230
  • 3
  • 17
  • 26
8
votes
1 answer

Why does AspectJ @Around advice execute twice?

I have the following AspectJ example that I've done as a "hello world" style proof of concept. The advising code in the StyleAspect seems to execute twice even though the actual code in SomeClass only executes once (as required). Here's the…
PhilDin
  • 2,802
  • 4
  • 23
  • 38
8
votes
1 answer

aspectj and spring with aspectj-autoproxy

I've declared my aspects using the @Aspect annotation, but the advice does not seem to get applied. The aspect works in a few other projects that I have, and the key difference seems to be that the other projects are completely wired using…
Kevin
  • 24,871
  • 19
  • 102
  • 158
8
votes
1 answer

AspectJ in Android: pointcut call(* Activity.onCreate(..)) doesn't pick out Activity.onCreate() calls

I am using AspectJ in my Android project and I'd like to write a pointcut that catches all the calls to onCreate() and onDestroy() of my activities. I am quite new to AspectJ, so probably I am missing something here but why this: pointcut…
futtetennista
  • 1,876
  • 1
  • 20
  • 33
8
votes
5 answers

Spring aspectj jar not configured correctly

I am getting this error when I tried to use a JPA object created by Roo. Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?) I have followed some online advice to add the…
newguy
  • 5,668
  • 12
  • 55
  • 95
8
votes
2 answers

How to swallow a exception at AfterThrowing in AspectJ

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…
user389227
  • 141
  • 1
  • 5