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
12
votes
3 answers

Log the return value of a method using spring aop

I have a method which returns an object. I would like to print that object's value in my log using spring AOP. How can I achieve that? Please help!
prabu
  • 1,247
  • 7
  • 21
  • 33
12
votes
2 answers

Testing a Spring AOP Aspect

When writing aspects, how can I test that they do match and that they are invoked when I want them to? I'm using @Aspect declarations with Spring 2.5.6. I don't care about the functionality, that's extracted and tested otherwise.
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
11
votes
2 answers

Enable Spring AOP or AspectJ

This is following on from this question: Spring autowired bean for @Aspect aspect is null My initial understanding was that when using Spring AOP, classes annotated with @Aspect are created as spring managed beans, so dependency injection would work…
mogronalol
  • 2,946
  • 8
  • 38
  • 56
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
3 answers

Spring 3 MVC @Controller with AOP interceptors?

Anyone knows why apparently it is not possible to use AOP with annotated MVC Controllers? (see Post). I have a @Controller that stops working as soon as I add a pointcut to it. The problem is not that the interceptor is not being called, but rather…
pakman
  • 1,676
  • 3
  • 23
  • 41
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

Custom Spring AOP Around + @Transactional

I have a custom Around implemented to match on a custom Annotation. I want the custom around to execute WITHIN the outer @Transactional. Unfortunately, this doesn't appear to work. (The AOP is working. I see stacktraces that show it). The stack…
Virmundi
  • 2,497
  • 3
  • 25
  • 34
11
votes
2 answers

What is the difference between @Before @After and @AfterExecution in Spring aop

I have started learning Spring AOP. Can I have a brief description on @Before @After and @AfterExecution. Among those three annotations am confused with @Before and @After because both are executed before the start of the method execution. Can I…
11
votes
2 answers

Retrieve parameter value from ProceedingJoinPoint

In my Request i have a parameter name "accessToken", how do i get request parameter value from ProceedingJoinPoint ? public Object handleAccessToken(ProceedingJoinPoint joinPoint) throws Throwable { final Signature signature =…
Shamseer PC
  • 787
  • 2
  • 9
  • 20
11
votes
3 answers

How to exclude methods from aspectj

I'm trying to exclude several methods from log files using aspectj (Im usong spring and Load-time weaving). Is there a way to list the excluded methods in the aop.xml? I know i can do this for full classes but I'm looking for specific methods. or…
lior
  • 1,127
  • 3
  • 24
  • 43
11
votes
2 answers

Cannot find a spring-aspects-4 dependency

I want to upgrade my project to spring 4, however, I get a missing dependency for aspectweaver-1.8.0.M1.jar. When I take a look at the dependency hierarchy, I see that this file is needed by spring-aspects-4.0.0, which has the following in its own…
Serafeim
  • 14,962
  • 14
  • 91
  • 133
11
votes
2 answers

I'm getting the following exception when following the JavaBrains tutorial on Spring Aspect Programming:

I'm following the spring aspect programming tutorials at Javabrains. I'm in this tutorial specifically: http://javabrains.koushik.org/2011/08/spring-tutorial-27-writing-our-first.html I have the required libraries imported into the project and I get…
Felipe
  • 315
  • 2
  • 3
  • 10
11
votes
1 answer

Spring AOP and aspect thread safety for an autowired HTTPServletRequest bean

I am using Spring 3 AOP, and I have an aspect that requires access to the HttpServletRequest. It looks something like this: @Aspect public class MyAspect { @Autowired private HttpServletRequest httpServletRequest; public void init() { …
user4903
10
votes
2 answers

Spring AOP: Annotation on any method called x not working

I am getting started with AOP for the first time. I have my first aspect as follows: @Aspect public class SyncLoggingAspect { private final Logger logger = Logger.getLogger(this.getClass()); @Before("execution(public * *(..))") public…
mogronalol
  • 2,946
  • 8
  • 38
  • 56
10
votes
6 answers

Why Spring AOP is not weaving external jars at runtime?

I have a java application build upon Spring 3. This project has another jar as a dependency. This dependency contains a @org.aspectj.lang.annotation.Aspect class (lets say, com.aspectprovider.aspects.MyAspect). There's a @Before advice to weave a…
bluefoot
  • 10,220
  • 11
  • 43
  • 56