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
14
votes
2 answers

How to write an Aspect pointcut based on an annotated parameter

I'm having a bit of trouble working out how to create a pointcut that will operate on beans that have a specific annotated parameter. My eventual aim is to validate the value of the parameter before it's processed, but for the moment I just need to…
Stormcloud
  • 2,065
  • 2
  • 21
  • 41
14
votes
1 answer

When using spring aop:around, how can I get return type of the pointcut method?

I have a requirement now, that is when using mybatis(especially those batch execute sql), check parameter first , if the parameter is null or empty , then just return, don't proceed and if the return type is List,eg. List getByIds(List
zhuguowei
  • 8,401
  • 16
  • 70
  • 106
14
votes
3 answers

Spring AOP pointcut for all methods in a controller

I want to run some code before every method in a Spring (3.2.3) @Controller. I have the following defined but it won't run. I suspect the pointcut expression is incorrect. dispatcher-servlet.xml
Goose
  • 802
  • 1
  • 10
  • 22
14
votes
2 answers

AspectJ pointcut for annotated PRIVATE methods

I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method like below. @Aspect public class ServiceValidatorAspect { …
citress
  • 889
  • 3
  • 13
  • 35
14
votes
13 answers

AOP : java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut

I am new to AOP. I got some problem like this. package org.suman.Aspect; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; @Aspect public class LoginAspect { …
user1379705
  • 141
  • 1
  • 1
  • 4
13
votes
3 answers

AspectJ Load time weaver doesn't detect all classes

I am using Spring's declarative transactions (the @Transactional annotation) in "aspectj" mode. It works in most cases exactly like it should, but for one it doesn't. We can call it Lang (because that's what it's actually called). I have been able…
waxwing
  • 18,547
  • 8
  • 66
  • 82
13
votes
5 answers

How to instrument / advice a Spring Data (JPA) repository?

I'm failing in my effort to advice a spring data jpa repository. The goal is to instrument (around) all non-void public methods in a particular repository annotated with a custom annotation (ResourceNotFound in this example) and throw an exception…
epdittmer
  • 488
  • 2
  • 4
  • 15
13
votes
5 answers

Spring AOP: how to get the annotations of the adviced method

I'd like to implement declarative security with Spring/AOP and annotations. As you see in the next code sample I have the Restricted Annotations with the paramter "allowedRoles" for defining who is allowed to execute an adviced method. …
hugri
  • 1,416
  • 3
  • 18
  • 32
13
votes
1 answer

The Old "@Transactional from within the same class" Situation

Synopsis of the original question: Using standard Spring Transactions with AOP proxying, it is not possible to call an @Transactional-marked method from a non-@Transactional-marked method in the same class and be within a transaction (specifically…
Random Human
  • 946
  • 1
  • 14
  • 31
13
votes
3 answers

Log4j and AOP, how to get actual class name

I'm implementing a logger as an aspect using Spring AOP and Log4J, but I've noticed that the class name in log file is always the LoggerAspect class name, so... is there a way to trace the actual class name in my log?
davioooh
  • 23,742
  • 39
  • 159
  • 250
12
votes
3 answers

Configurable vs Component with Spring and AspectJ

When using AspectJ, why use @Component over @Configurable. I've got Spring and AspectJ setup for @Transactional support, aspects on self-invocation, and injection into JPA entities. This works great. I'm using @Component for most classes that need…
DragonFax
  • 4,625
  • 2
  • 32
  • 35
12
votes
6 answers

java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

Thinker.java package springdemo2; public interface Thinker { void thinkOfSomething(String thoughts); } Volunteer.java package springdemo2; public class Volunteer implements Thinker{ private String thoughts; @Override public…
rohit
  • 602
  • 4
  • 11
  • 24
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
4 answers

How efficient is Spring AOP in case of memory consumption

In my pet project i have a long running job, i want to show the status to the user about the process and how far it went. So am pushing the status objects to JMS topic from there am picking up the and feeding to WS app to stream them to a valid…
mallikarjun
  • 1,862
  • 5
  • 23
  • 47
12
votes
4 answers

Aspect not being called in Spring test

I am using Spring 4.16 and i have my ValidationAspect, which validates methods arguments and throws ValidationException if is something wrong. This is being called when i run the server and send requests, but not when comes from the test: package…
jscherman
  • 5,839
  • 14
  • 46
  • 88