Oct 4th, 2012, 06:38 PM
JUnit and AspectJ woven classes problem
I'm using aspectJ compile time weaving of our own custom Aspect and for @Transactional handling in our spring application. Everything works fine normally but I just noticed the JUnit tests are performing oddly.
We use the SpringJunit4ClassRunner to instantiate everything in the unit tests and all all our non aspect woven beans operate correctly. For the ones using Aspects however, based on tracing it looks like they are not singletons and being constructed multiple times which causes all kind of weirdness.
Based on my read of the docs Iíve added explicit bean definitions for both aspects that being used:
<bean class="org.springframework.transaction.aspectj.Ann otationTransactionAspect" factory-method="aspectOf">
<property name="transactionManager" ref="txManager"/>
<bean class="com.path.metrics.MetricsAspect" factory-method="aspectOf">
<property name="metricsInstance" ref="GlobalMetricsInstance"/>
But that has had no effect. Does anyone know how to get this type setup to work correctly or have some advice?