Question

I need to make a check in my pointcut expression like. I have this bean:

<bean id="logConfig"
    class="com.celfocus.ufe.base.logging.domains.LoggingConfiguration">
    <property name="logDetails" value="STANDARD" />
    <property name="logLvl" value="COMPLETE" />
</bean>

In my aop pointcut expression i need to make a check to verify the value of bean property "logLvl".

<aop:config>
    <aop:aspect ref="ufeLogger">
        <aop:pointcut id="complete" expression="execution(* *.*(..)) and bean(logConfig)==COMPLETE" />
        <aop:before pointcut-ref="complete" method="logBefore" />
    </aop:aspect>
</aop:config>

My expression isn't working... what I can change to make this check?

Was it helpful?

Solution

What makes you think that and bean(logConfig)==COMPLETE is a valid pointcut? Spring AOP uses AspectJ pointcut syntax, no Spring additions. Also you are not even referencing logLvl property, so has is this suppose to work?

Unfortunately to achieve this you must implement check manually. This isn't so intrusive though: simply inject logConfig into ufeLogger aspect and add a simple condition in logBefore() method.

OTHER TIPS

This is the most relevant question, for solution below. I write aspect expressions from time to time. And expression might not work. You need to write right expression, which will be matched with your target method. I found a simple decision to check that everything is clear:

@Around(value="execution(* *.find(..))")
public Entity filterEntity(ProceedingJoinPoint pjp) throws Throwable {
   Entity entity = (Entity) pjp.proceed(); // put breakpoint here
}

In Debug mode you can check target method real signature that is used for match with expression, in path pjp.methodInvocation.method

I hope this answer will save your time to find an error.

P.S If there are exists better decision to check expressions, glad to see it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top