I am just getting started with Spring AOP in my project and am having some problems with getting Spring AOP working correctly.
I have two objects, TransportImpl and SesssionImpl that I would like to profile via AOP. Both objects(beans) are initialised via Spring. Both beans are implementations of business interfaces (Transport and Session). I can get Aspects applied to the TransportImpl bean to work well, but those applied to the SessionImpl just do not fire. I can confirm that the "mySessionMonitor" Aspect is initialised by Spring, and that the SessionImpl object is also initialised without any exceptions or errors.
I have stripped down my PointCuts and Aspect to the most basic form possible. I would have expected the PointCut sessionOperation described below to fire when the SessionImpl bean is initialised and the init-method initialise is called. But this never happens. What might be going wrong here?
From the configuration file:
<bean id="MyTransport" class="my.app.transport.TransportImpl" scope="singleton" />
<bean id="MySession" class="my.app.session.SessionImpl" init-method="initialise" scope="singleton" />
<aop:aspectj-autoproxy proxy-target-class="true">
<aop:include name="myTransportMonitor" />
<aop:include name="mySessionMonitor" />
</aop:aspectj-autoproxy>
<bean id="myTransportMonitor" class="my.app.aspects.TransportMonitoringAspect"/>
<bean id="mySessionMonitor" class="my.app.aspects.SessionMonitoringAspect" />
Aspect code
// Aspect monitoring code
@Aspect
public class SessionMonitoringAspect
{
private Logger fileLogger = Logger.getLogger("myLogger");
public void initialise()
{
fileLogger.info("Initialising SessionMonitoringAspect");
}
@Pointcut ("execution (public * *(..))")
private void anyPublicOperation(){}
@Pointcut ("within(my.app.session..*)")
private void inSession(){}
@Pointcut("anyPublicOperation() && inSession()")
private void sessionOperation(){}
@Before("sessionOperation()")
public void sessionOperationDetected(JoinPoint jp)
{
fileLogger.info("Session operation detected - signature: " + jp.getSignature());
}
}