Questions tagged [spring-aop]

Spring AOP is the Spring Framework's version of AOP, implemented in pure Java and using the @AspectJ annotations from the AspectJ project. Spring AOP works through dynamic JDK or CGLib Proxies.

Spring AOP is explained in the

Spring 3.0.x Online Reference > 7. Aspect Oriented Programming with Spring

Note that there is an increasing tendency to replace Spring AOP with static AspectJ compilation. This Approach is explained in Section: 7.8 Using AspectJ with Spring applications

AspectJ in Action is an excellent reference for both Spring AOP and AspectJ

The pre-3.0 XML-based Spring AOP approach is explained in Appendix B. Classic Spring AOP Usage

2584 questions
22
votes
1 answer

Spring AOP - pointcut for every method with an annotation

I am trying to define a pointcut, that would catch every method that is annotated with (i.e.) @CatchThis. This is my own annotation. Moreover, I'd like to have access to the first argument of the method, which will be of Long type. There may be…
emesx
  • 12,555
  • 10
  • 58
  • 91
22
votes
2 answers

Spring AOP AfterThrowing vs. Around Advice

when trying to implement an Aspect, that is responsible for catching and logging a certain type of error, I initially thought this would be possible using the AfterThrowing advice. However it seems that his advice doesn't catch the exception, but…
whiskerz
  • 299
  • 1
  • 3
  • 7
22
votes
3 answers

Spring AOP Pointcut syntax for AND, OR and NOT

I'm having trouble with a pointcut definition in Spring (version 2.5.6). I'm trying to intercept all method calls to a class, except for a given method (someMethod in the example below).
Odinodin
  • 2,147
  • 3
  • 25
  • 43
21
votes
5 answers

Spring AOP pointcut for annotated argument

Say I have a method like so: public void method(@CustomAnnotation("value") String argument) Is there a pointcut expression that could select all methods with arguments annotated with @CustomAnnotation? If so is there a way I could get access go…
mogronalol
  • 2,946
  • 8
  • 38
  • 56
20
votes
4 answers

Disabling certain aspects during unit test runs

I have integration tests (load context) and unit tests running together. My code does aspectj compile time weaving using spring. My problem is that my declared advises also run during some of my unit tests. This kills the notion of a unit test,…
netta
  • 508
  • 6
  • 16
20
votes
1 answer

Why does self-invocation not work for Spring proxies (e.g. with AOP)?

Please explain, why self invocation on proxy performed on target but not proxy? If that made on purpose, then why? If proxies created by subclassing, it's possible to have some code executed before each method call, even on self invocation. I tried,…
krund
  • 740
  • 1
  • 7
  • 16
20
votes
1 answer

Spring self injection for transactions

In Spring you can't simply call @Transactional method from the same instance, because of AOP-proxy thing. Would it be nice idea to make a self injection and call that method from self proxy instance? Do you see any drawbacks?
gs_vlad
  • 1,409
  • 4
  • 15
  • 29
20
votes
1 answer

Pointcut for annotated methods or methods in annotated classes

I need a pointcut for methods in classes annotated with @X or methods annotated with @X. I also need the annotation object. If both the class and the method are annotated I prefer to get the method annotation as argument. I tried the following,…
ASA
  • 1,911
  • 3
  • 20
  • 37
20
votes
3 answers

Spring AOP change value of methods argument on around advice

Is it possible to change method argument value on basis of some check before executing using Spring AOP My method public String doSomething(final String someText, final boolean doTask) { // Some Content return "Some Text"; } Advice…
Ashish Aggarwal
  • 3,018
  • 2
  • 23
  • 46
20
votes
3 answers

Java Spring AOP: Using CustomizableTraceInterceptor with JavaConfig @EnableAspectJAutoProxy, not XML

Spring AOP has a method-level tracer called CustomizableTraceInterceptor. Using Spring's XML configuration approach, one would set up this tracer like so:
Abdull
  • 26,371
  • 26
  • 130
  • 172
18
votes
2 answers

Mixing JDK and CGLIB proxies within Spring

I have an application running with Spring, and I'm using AOP in some places. Since I want to use the @Transactional annotation at interface level, I have to allow Spring to create JDK proxies. So, I don't set the proxy-target-class property to true.…
Thiago Coraini
  • 311
  • 2
  • 7
18
votes
2 answers

Spring AOP Exclude Some Classes

I'm using Spring AspectJ for logging method execution statistics, however, I want to exclude some classes and methods from this without changing the pointcut expression. To exclude certain methods I created a custom annotation which I use to filter…
Harshil Sharma
  • 2,016
  • 1
  • 29
  • 54
18
votes
4 answers

Exception java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Aspect

I recently started working on AspectJ and wrote a simple Aspect for Logging. I have defined below dependencies into my pom file: org.aspectj aspectjrt
Atul
  • 1,694
  • 4
  • 21
  • 30
18
votes
2 answers

Spring @Transactional in an Aspect (AOP)

I've created an Aspect which contains an @Transactional annotation. My advice is being invoked as expected, but the new entity AuditRecord is never saved to the database, it looks like my @Transactional annotation is not…
levacjeep
  • 673
  • 3
  • 6
  • 23
18
votes
3 answers

java.lang.IllegalArgumentException: warning no match for this type name: ru.sbt.filial.cards.aspect.SomeBean [Xlint:invalidAbsoluteTypeName]

I never used Spring AOP and trying to configure my first bean. It seems that I configured it properly, but I get an exception that the bean is not found. My aspect is – @Aspect @Component public class IdentificationAspect { …
Dmitry Bakhtiarov
  • 373
  • 1
  • 5
  • 14