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 to make an AspectJ Aspect work in a Gradle project?

I am using the following sample code to understand AspectJ: public class Account { int balance = 20; public boolean withdraw(int amount) { if (balance < amount) { return false; } balance = balance -…
F. K.
  • 694
  • 3
  • 9
  • 23
9
votes
3 answers

Intellij + Ajc + Lombok/Mapstruct

I want to enable AspectJ compiler in my IntelliJ Idea as I have several aspects that I'd like to be woven during compile time. At the same time, I am using Lombok and Mapstruct in my codebase. Those 2 require additional annotations processing, that…
Ihor M.
  • 2,728
  • 3
  • 44
  • 70
9
votes
2 answers

AspectJ JoinPoint question

I am currently using JoinPoint to capture the parameters passed to service methods at runtime. Though JoinPoint helps me retrieve the parameter values, I see that it doesn't provide any good API to retrieve the names of the parameters, parameter…
soontobeared
  • 441
  • 4
  • 9
  • 30
9
votes
1 answer

AspectJ compiler (ajc) vs load-time weaving

Several questions here: Does ajc change all the classes it compiles (even non-aspect ones)? What if I compile only aspect classes ant then put them in the same classpath with the common ones? Does the ajc-compiled project perform faster then the…
weekens
  • 8,064
  • 6
  • 45
  • 62
9
votes
2 answers

Access a business method's local variable in a method which is in an ASPECT

I want to access a local variable from a method in a business class, in a method which is in an aspect class. For instance class BusinessClass { public void simpleTest() { ... String localString = new String( "test" ); …
lupchiazoem
  • 8,026
  • 6
  • 36
  • 42
9
votes
0 answers

Aspect around Kotlin suspended function

What is the right way to create an aspect around Kotlin suspended function? From my observation, Micrometer's @Timed aspect does work with them, but shows incorrect result - looks like it measures time between method invocation and suspension, not…
silent-box
  • 1,649
  • 3
  • 21
  • 40
9
votes
1 answer

Using AspectJ LTW to allow spring proxy functionalty on self-invocation of non-public methods and related considerations

I have seen numerous examples of Spring functionality related to @Cacheable, @Transactional, @Async, etc. where the same options are reiterated every time: Self invocation made through a proxy object gotten through either the…
filpa
  • 3,651
  • 8
  • 52
  • 91
9
votes
1 answer

AspectJ compiler bug leads to StackOverflowError

I run into a StackOverflow error of the AspectJ compiler today and I thought I should share it on StackOverflow :-) To reproduce the error I made a toy example public abstract class Node> implements WithParent{ private T…
Emanuele Fusco
  • 809
  • 6
  • 11
9
votes
1 answer

Aspects scanning too many classes and method cache fills memory

In our application we have several (actuall many, about 30) web services. Each web service resides in its own WAR file and has its own Spring context that is initialised when application starts. We also have a number of annotation-driven aspect…
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
9
votes
1 answer

AspectJ matching return type as interface with generics

I'm trying to create an AspectJ Aspect to intercept the returning methods that has a generic interface. This is my AspectJ @AspectJ public class MyAspect { @AfterReturning("execution(java.util.Collection+
Beto Neto
  • 3,962
  • 7
  • 47
  • 81
9
votes
1 answer

Is there an AspectJ pointcut expression that searches all subpackages?

So I've got an aspect with a method declared with the following expression: @Before("execution(* aaa.bbb.ccc.*.*(..))") This works perfectly for all classes in the package aaa.bbb.ccc. Now, however, I would like to capture all classes in aaa.bbb,…
asteri
  • 11,402
  • 13
  • 60
  • 84
9
votes
3 answers

Running JDK8 for aspectj

I am trying to run aspectj-maven plugin with JDK8. But it is giving errors like "The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files" Any help on how to resolve, or if the aspectj-maven-plugin…
Deepesh Nathani
  • 93
  • 1
  • 1
  • 4
9
votes
1 answer

Checking whether or not entities/objects belong to the currently logged-in user with Spring

I am working on a Spring web application that uses: Spring MVC Spring Core Spring Roo Spring Security Spring Data JPA Mysql The issue I have is as follows: for each access from the web layer to the application's entities/objects I want to be able…
balteo
  • 23,602
  • 63
  • 219
  • 412
9
votes
2 answers

Why aspect j can't weave show Xlint cantFindType

I have write a aspectj class,and i want weave by autodetect like but it's does't effect. show some errors: [TomcatInstrumentableClassLoader@14d659d] error can't determine annotations of missing type…
nabilzhang
  • 103
  • 1
  • 1
  • 3
9
votes
3 answers

Aspect weaving at runtime

I'm looking for a Java solution that would allow me to use AOP to weave new code on top of already running code at runtime. The key is not to require the restart of the JVM. Also, I'd like to remove the woven at runtime, leaving the old code running…
Faustas
  • 350
  • 1
  • 2
  • 10