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
197
votes
9 answers

Spring @Transaction method call by the method within the same class, does not work?

I am new to Spring Transaction. Something that I found really odd, probably I did understand this properly. I wanted to have a transactional around method level and I have a caller method within the same class and it seems like it does not like…
Mike
  • 1,981
  • 2
  • 12
  • 4
192
votes
8 answers

Spring AOP vs AspectJ

I am under the impression that Spring AOP is best used for application specific tasks such as security, logging, transactions, etc. as it uses custom Java5 annotations as a framework. However, AspectJ seems to be more friendly design-patterns wise.…
zotherstupidguy
  • 2,976
  • 10
  • 39
  • 59
156
votes
10 answers

@AspectJ pointcut for all methods of a class with specific annotation

I want to monitor all public methods of all Classes with specified annotation (say @Monitor) (note: Annotation is at class level). What could be a possible pointcut for this? Note: I am using @AspectJ style Spring AOP.
Rejeev Divakaran
  • 4,384
  • 7
  • 36
  • 36
107
votes
18 answers

Spring AOP: What's the difference between JoinPoint and PointCut?

I'm learning Aspect Oriented Programming concepts and Spring AOP. I'm failing to understand the difference between a Pointcut and a Joinpoint - both of them seem to be the same for me. A Pointcut is where you apply your advice and a Joinpoint is…
Saurabh Patil
  • 4,170
  • 4
  • 32
  • 33
59
votes
2 answers

Getting the java.lang.reflect.Method from a ProceedingJoinPoint?

The question is short and simple: Is there a way to get the Method object from an apsectj ProceedingJoinPoint? Currently I am doing Class[] parameterTypes = new Class[joinPoint.getArgs().length]; Object[] args = joinPoint.getArgs(); for(int i=0;…
Erik
  • 11,944
  • 18
  • 87
  • 126
50
votes
3 answers

What is AspectJ good for?

First let me note, that I use AspectJ and I like it, but what else can I do with it. I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can…
Ralph
  • 118,862
  • 56
  • 287
  • 383
49
votes
1 answer

Unit testing Spring @Around AOP methods

I can unit test most of my Spring classes without needing to do Spring "stuff". I can unit test @Before advice methods without using Spring too: Example code: @Before("execution(* run(..)) && " + "" + "target(target) && " + …
slim
  • 40,215
  • 13
  • 94
  • 127
46
votes
8 answers

java.lang.IllegalStateException: No thread-bound request found, exception in aspect

Following is my aspect: @Configurable @Aspect public class TimingAspect { @Autowired private HttpServletRequest httpServletRequest; // Generic performance logger for any mothod private Object…
hrishikeshp19
  • 8,838
  • 26
  • 78
  • 141
40
votes
5 answers

Maven + AspectJ - all steps to configure it

I have a problem with applying aspects to my maven project. Probably I am missing something, so I've made a list of steps. Could you please check if it is correct? Let say in projectA is an aspect class and in projectB classes, which should be…
alicjasalamon
  • 4,171
  • 15
  • 41
  • 65
38
votes
10 answers

Spring autowired bean for @Aspect aspect is null

I have the following spring configuration:
mogronalol
  • 2,946
  • 8
  • 38
  • 56
38
votes
2 answers

@Transactional in super classes not weaved when using load time weaving

The project I am working on has a similar structure for the DAOs to the one bellow: /** * Base DAO class */ @Transactional public class JPABase { @PersistenceContext private EntityManager entityManager; public void persist(Object…
38
votes
5 answers

Spring AOP - why do i need aspectjweaver?

i wrote a very simple Aspect with Spring AOP. It works, but i have some problems understanding what is really going on. I don't understand why i have to add the aspectjweaver.jar? The Spring-AOP documentation clearly states that i don't need aspectj…
Mario B
  • 2,102
  • 2
  • 29
  • 41
37
votes
10 answers

Spring autowiring using @Configurable

I'm playing with the idea of using Spring @Configurable and @Autowire to inject DAOs into domain objects so that they do not need direct knowledge of the persistence layer. I'm trying to follow…
optilude
  • 3,538
  • 3
  • 22
  • 25
36
votes
1 answer

Aspect oriented programming - what is 'cflow'?

I have referred to the AspectJ reference here it states that the 'cflow' is cflow(Pointcut) - every join point in the control flow of each join point P picked out by Pointcut, including P itself This isn't entirely lucid for me and I was…
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
34
votes
6 answers

How to use AOP with AspectJ for logging?

I would like to add "trace" messages to all my public methods as follows: public void foo(s:String, n:int) { // log is a log4j logger or any other library log.trace(String.format("Enter foo with s: %s, n: %d", s, n)) ... log.trace("Exit foo")…
Michael
  • 10,185
  • 12
  • 59
  • 110
1
2 3
99 100