Search code examples
springaopexpressionpointcut

Make a check on AOP pointcut expression


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?


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.