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

@AspectJ pointcut for all methods inside package

I have this working code for a specific package, but i want to configure it for all controllers, service and dao…
Mohan Seth
  • 761
  • 2
  • 11
  • 20
33
votes
3 answers

Is using Spring AOP for logging a good idea?

I'm reading up on Spring at the moment and one of the examples used for a use of AOP is logging the start and end of method calls. I've also read that using AOP can impact performance. Is using Spring AOP a good idea for this type of logging? My…
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
32
votes
1 answer

Spring AOP works without @EnableAspectJAutoProxy?

I am learning Spring (currently its AOP framework). Even though all sources I've read say that to enable AOP one needs to use @EnableAspectJAutoProxy annotation (or its XML counterpart) my code seems to work with annotation commented out. Is that…
lukeg
  • 4,189
  • 3
  • 19
  • 40
31
votes
3 answers

Get AOP proxy from the object itself

Is possible to get the proxy of a given object in Spring? I need to call a function of a subclass. But, obviously, when I do a direct call, the aspects aren't applied. Here's an example: public class Parent { public doSomething() { …
sinuhepop
  • 20,010
  • 17
  • 72
  • 107
31
votes
3 answers

Spring AOP: Getting parameters of the pointcut annotation

Consider I have defined the following aspect: @Aspect public class SampleAspect { @Around(value="@annotation(sample.SampleAnnotation)") public Object display(ProceedingJoinPoint joinPoint) throws Throwable { // ... } } and the…
Erik
  • 11,944
  • 18
  • 87
  • 126
29
votes
3 answers

error Type referred to is not an annotation type:

I got the following Aspect @Around("execution(public * (@DisabledForBlockedAccounts *).*(..))" + " && @annotation(denyForTeam)") public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny) throws Throwable { Account…
Acdc RocknRoll
  • 677
  • 5
  • 9
  • 16
28
votes
4 answers

Obtain real Class object for Spring bean

I am using Spring to inject beans. And I am using some annotations to annotate bean methods (Security, TransactionManagement, ExceptionHanling, Logging). The problem is: I want to create JUnit test to check if I forgot annotate some methods. But…
Pavel Vyazankin
  • 1,470
  • 6
  • 18
  • 27
26
votes
1 answer

JUnit tests for AspectJ

I am trying to write Junit tests for Custom Aspect. Here is the Aspect Class Snippet: @Aspect @Component public class SampleAspect { private static Logger log = LoggerFactory.getLogger(SampleAspect.class); @Around("execution(*…
karthik
  • 773
  • 2
  • 11
  • 19
26
votes
10 answers

AspectJ expression gives formal unbound in pointcut error

I have within aspectJ the expression: @Pointcut("within(com.param.cpms.dao.impl.ProjectMetaDaoImpl)") public void daoExceptionHandle() { } At Spring 3.0 startup, I am getting the following error : nested exception is…
param
  • 261
  • 1
  • 3
  • 3
25
votes
4 answers

Why doesn't AspectJ compile-time weaving of Spring's @Configurable work?

Update 5: I've downloaded the latest Spring ToolsSuite IDE based on the latest Eclipse. When I import my project as a Maven project, Eclipse/STS appears to use the Maven goals for building my project. This means AspectJ finally works correctly in…
Robert Campbell
  • 6,848
  • 12
  • 63
  • 93
24
votes
6 answers

Spring AOP target() vs this()

From Spring Documentation: any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface: this(com.xyz.service.AccountService) any join point (method execution only in Spring AOP) where the…
rapt
  • 11,810
  • 35
  • 103
  • 145
23
votes
4 answers

How to specify single pointcut for multiple packages

I am using Aspect for logging activities in my spring mvc based application. I am using @controller annotations to define any controller in my application. I have two different controller in two different package say com.package1 contains…
Ketan
  • 2,612
  • 5
  • 31
  • 44
23
votes
2 answers

How to inject HttpServletRequest into a Spring AOP request (custom scenario)?

I know the standard way of writing an AOP advice around a controller method and that you can get access to the HttpServletRequest arg, if declared in controller method. But my scenario is that I have a translation service, that is currently…
Paddy
  • 3,472
  • 5
  • 29
  • 48
23
votes
4 answers

Joinpoint VS ProceedingJoinPoint in AOP using aspectJ?

Can any one tell me what is the difference between Joinpoint and Proceedingjoinpoint? When to use Joinpoint and Proceedingjoinpoint in the method of aspect class? I used the JoinPoint in my AspectJ class like: @Pointcut("execution(*…
Human Being
  • 8,269
  • 28
  • 93
  • 136
23
votes
7 answers

Spring AOP (Aspect) Not executing

I ams using Spring 2.5.6, asm 1.5.3, aspectjrt/aspectjweaver 1.6.1, cglib 2.1_3 In my Web based Spring application I have following class: package uk.co.txttools.aspects; @Aspect public class LoggingAspect { @Before("execution(*…
bhavin
  • 337
  • 1
  • 2
  • 9