Announcement Announcement Module
No announcement yet.
Subclassing AbstractTransactionAspect and @AspectJ Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Subclassing AbstractTransactionAspect and @AspectJ

    Hi all

    I had the problem of adding aspects to non spring-managed objects. For this reason I've resorted to AspectJProxyFactory and it works like a charm.

    Now, the aspect I needed to apply is one that adds transaction demarcation to these objects; since I don't personally like the @Transactional approach I'd understood that I needed to subclass AbstractTransactionAspect.

    My question lies here: to avoid having to compile .aj aspects I had thought of extending AbstractTransactionAspect with an @Aspect thus resulting in something like

    public class TransactionAspect2 extends AbstractTransactionAspect {
        protected TransactionAspect2() {
        @Pointcut("execution(* org.atalaya.isec.update.RemoteUpdateThread.*(..))")
        protected void transactionalMethodExecution() {
    Nevertheless when trying to pass this aspect to the proxy factory I get

    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.atalaya.isec.aop.update.UpdateAspect]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Expecting to find 2 arguments to bind by name in advice, but actually found 1 arguments.
    Caused by: java.lang.IllegalStateException: Expecting to find 2 arguments to bind by name in advice, but actually found 1 arguments.
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.bindExplicitArguments(
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.bindArgumentsByName(
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.calculateArgumentBindings(
    	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvice(
    	at org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl.instantiateAdvice(
    	at org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl.<init>(
    	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisor(
    	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory$1.doWith(
    	at org.springframework.util.ReflectionUtils.doWithMethods(
    	at org.springframework.util.ReflectionUtils.doWithMethods(
    	at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisors(
    	at org.springframework.aop.aspectj.annotation.AspectJProxyFactory.addAdvisorsFromAspectInstanceFactory(
    	at org.springframework.aop.aspectj.annotation.AspectJProxyFactory.addAspect(
    Actually a simple workaround has been to rewrite AbstractTransactionAspect as an @Aspect and the same setup works fine. I still don't know if what I've accomplished makes any sense generally speaking. And actually I don't have an explanation of why it's not legal to extend an aspect with an @Aspect...

    Thanks a lot for any comment