1

Is it possible to use same aspect method for multiple pointcuts but with different parameters given from xml? Something like this(1 and 2 are parameters) :

<!-- Aspect -->
<bean id="logAspect" class="LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLoggging" ref="logAspect" >
    <aop:pointcut id="testAround" expression="execution(* methodA(..))" />
    <aop:pointcut id="testAroundC" expression="execution(* methodC(..))" />

    <!-- @Around -->
    <aop:around method="logProcess(1)" pointcut-ref="testAround" />
    <aop:around method="logProcess(2)" pointcut-ref="testAroundC" />
</aop:aspect>

When I call methodA I want logProcess method to output 1 and when I call methodC I want logProcess method to output 2

My logProcess method :

public Object logProcess(ProceedingJoinPoint joinPoint) throws Throwable {}

Spring @Transactional wont rollback after putting aspect around method

Community
  • 1
  • 1
Juka
  • 37
  • 1
  • 9
  • I don't think so. Why would you want to do that? – Andrei Stefan May 20 '14 at 12:31
  • Because I have multiple processes(methods) that have their id-s witch i want to write in DB before and after execution of those methods. and I dont want to rewrite same method but with different parameters (logProcess) for every method I want to wrap around. – Juka May 20 '14 at 12:36

1 Answers1

0

I'm pretty sure not.

However you can generally achieve this kind of functionality by utilising the ProceedingJoinPoint object that you have as a parameter:

public Object logProcess(ProceedingJoinPoint joinPoint) throws Throwable

    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    if(method.getName().equals("methodA")) {

    }
    //etc..
StuPointerException
  • 7,117
  • 5
  • 29
  • 54
  • Well, this is very useful. I can connect these id-s with method names in DB and I don't need multiple if statements. Thanks! – Juka May 20 '14 at 12:44