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
12
votes
1 answer

Aspectj overwrite an argument of a method

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)…
eglobetrotter
  • 718
  • 4
  • 10
  • 25
12
votes
1 answer

How does AspectJ work?

I am trying to understand how Aspect works. I come from a C/C++ background where magic never happens. I understand that you can annotate some functions with @Aspect then write down the Aspect implementation and so on. But, how (and at what time)…
Kam
  • 5,878
  • 10
  • 53
  • 97
12
votes
3 answers

How to Configure AspectJ in Android Studio

I am trying to configure AspectJ in Android Studio. But after all trial and error its not working ! Surprisingly I am able to make it work with Eclipse Kepler version The steps I followed for Android Studio Created sample Android Project File >…
Sreehari
  • 5,621
  • 2
  • 25
  • 59
12
votes
1 answer

This() vs Target() aspectj

Can anyone explain the difference between this() and target() pointcuts in aspectj. I tried finding this elsewhere but there doesnt seem to be a clear cut answer. Thank You
Sam
  • 293
  • 3
  • 19
12
votes
2 answers

Pointcuts on inherited methods (in a class design-agnostic context)

I am fiddling around with AspectJ and came up with an idea that I don't seem to be able to implement properly (story of my life). I have defined an aspect : package my.package; import org.aspectj.lang.annotation.*; import…
Ar3s
  • 2,237
  • 2
  • 25
  • 47
12
votes
1 answer

Tool for java that uses annotation to monitor/log/report threads accessing given method?

Context: I have created a small (java) multithread server for a game. Despite my best efforts of following the best practices it turned out that some methods that were intended to be called from just one thread got called from 2 or more threads.…
Ognyan
  • 13,452
  • 5
  • 64
  • 82
12
votes
2 answers

Spring AOP with AspectJ: Load time weaving

If I'm using AspectJ based Spring AOP, am I then tied to configuring my aspects to use load time weaving? Or does Spring AOP also support run time/compile time weaving when using the AspectJ based approach?
Shane
  • 461
  • 2
  • 8
  • 23
12
votes
1 answer

AspectJ + Junit + Maven - pointcut recognized in tests but NoSuchMethodError: aspectOf() exception thrown

I have followed almost all JUnit + Maven + AspectJ questions here and even I am pretty sure I have everything set properly, I am unable to test it. I have a Maven module with just one aspect: @Aspect public class AssertionAspect { …
stewenson
  • 1,282
  • 3
  • 15
  • 34
12
votes
2 answers

OSGi WeavingHook Examples

Does anybody have any examples of using the OSGi 4.3+ Weaving Hook Service? What about with AspectJ, ASM, JavaAssist? Is anybody actually using OSGi WeavingHooks? The example in OSGi Core 5.0.0 section 56.2 simply leaves out the actual weaving and…
John Ellinwood
  • 14,291
  • 7
  • 38
  • 48
11
votes
2 answers

Autowired dependency not injected in Aspect in Spring MVC

I am not able to @Autowire the Service Layer Instance in Aspect. In Aspect the reference to the @Autowired bean is NULL and it throws NullPointerException. Any help will be much appreciated. I think, I messed up with configuration. Following is my…
MUHAMMAD KHAN
  • 113
  • 1
  • 1
  • 4
11
votes
1 answer

AspectJ - pointcut for methods of interface's implementation

I have several implementations of SomeInterface. The question is what is the pointcut for the method executeSomething in all implementation of SomeInterface. public class SomeImplementation implements SomeInterface { public String…
Lenar
  • 419
  • 4
  • 19
11
votes
1 answer

IntelliJ IDEA + AspectJ

I am trying to use AspectJ in sample project in IntelliJ IDEA. I have an experience with Spring AOP, but this is first time I am using AspectJ, and cannot make it work. I am trying to do as described here:…
spam
  • 1,853
  • 2
  • 13
  • 33
11
votes
3 answers

spring 3.0 aop Pointcut is not well-formed: expecting 'name pattern' error

The following is my pointcut and advise declaration //PointCut on A method which takes two parameters and is in a DAO @Pointcut("execution(backend.repository.QuestionsRepository.AnswerQuestion (..))") public void answerQuestionPointCut()…
user463008
  • 113
  • 1
  • 1
  • 4
11
votes
3 answers

Running AspectJ causes NoSuchMethodError: Aspect.aspectOf

I have a very simple AspectJ aspect (using @AspectJ) which just prints out a log message. My goal is to advice code in my android application. Now this aspects works perfectly fine as long as I have the aspect class itself in my applications…
Flo
  • 1,469
  • 1
  • 18
  • 27
11
votes
5 answers

Spring AOP: @annotation(annotation)

I am (of course) trying to maintain a project using many constructs I don't know that well. In the course of attempting to figure out the AOP use within Spring, I came across methods with the following annotation: @Around(value =…
arcy
  • 12,845
  • 12
  • 58
  • 103