Announcement Announcement Module
Collapse
No announcement yet.
Basic AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Basic AOP

    This relates to Spring 2.0 (October Release)

    I have a basic AOP example working.. until I try to pass parameters - thows an exception telling me it cannot find the loging methods in the aspect.
    Here is the AppContext:
    Code:
    <aop:config>
     <aop:aspect id="loggingAspect" ref="simpleLogger">
    	<aop:before method="logTwoStrings"
    	pointcut="execution(* example..*Service.*(..)) and args(s1,s2)" />
    	<aop:after-returning method="logOneString" returning="s"
    		pointcut="execution(* example..*Service.*(..))" />
    		</aop:aspect>
    	</aop:config>
       <bean id="simpleLogger" class="example.SimpleLogger" />
    <bean id="concatService" class="example.ConcatServiceImpl" />
    Code:
    public class SimpleLogger {
    
       private static Log log = LogFactory.getLog(SimpleLogger.class);
    
       public void logOneString(String s) {
          log.info("string=" + s);
       }
    Code:
    public void logTwoStrings(String s1, String s2) {
          log.info("string1=" + s1 + ",string2=" + s2);
       }
    }
    Code:
    public interface ConcatService {
       public String concat(String s1, String s2);
    }
    Code:
    public class ConcatServiceImpl implements ConcatService {
    
       public String concat(String s1, String s2) {
          return s1 + s2;
       }
    }
    Last edited by jkidd; Feb 22nd, 2007, 08:57 AM.

  • #2
    Can you post the exact error message and call stack?

    -Ramnivas

    Comment


    • #3
      Please use code formatting also... Makes listings far easier to read.

      Comment


      • #4
        Stack Trace

        Code:
        Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot create inner bean '(inner bean)' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'simpleLogger' while setting bean property 'aspectBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#1': Cannot create inner bean '(inner bean)' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'simpleLogger' while setting bean property 'aspectBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#1': Cannot create inner bean '(inner bean)' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#1': Cannot create inner bean '(inner bean)' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
        Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
        Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V

        Comment


        • #5
          Check the version of your asm.jar in the classpath. It seems you have a wrong version of it around. Hibernate also ships an asm.jar.

          Regards,
          Andreas

          Comment


          • #6
            Well let it be known that ASM 3.0 seems to break some of the aspect functionality in Spring.. thanks for the tip...


            John

            Comment


            • #7
              You're welcome. Fine that it works now and thanks for sharing that information.

              Regards,
              Andreas

              Comment


              • #8
                stable versions for spring,aspectj &amp; asm

                When I try to execute this example, I am also getting the same error. Any body could help me for resolving it.

                aspectjrt & weaver 1.5.3
                spring aop2.0.5
                asm-3.1

                Please recommend the suitable versions for this samples.


                log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlA pplicationContext).
                log4j:WARN Please initialize the log4j system properly.
                Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
                Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
                Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;Z)V
                at org.springframework.core.LocalVariableTableParamet erNameDiscoverer.visitMethod(LocalVariableTablePar ameterNameDiscoverer.java:98)
                at org.springframework.core.LocalVariableTableParamet erNameDiscoverer.getParameterNames(LocalVariableTa bleParameterNameDiscoverer.java:54)
                at org.springframework.core.PrioritizedParameterNameD iscoverer.getParameterNames(PrioritizedParameterNa meDiscoverer.java:54)
                at org.springframework.aop.aspectj.AbstractAspectJAdv ice.bindArgumentsByName(AbstractAspectJAdvice.java :373)
                at org.springframework.aop.aspectj.AbstractAspectJAdv ice.calculateArgumentBindings(AbstractAspectJAdvic e.java:344)
                at org.springframework.aop.aspectj.AbstractAspectJAdv ice.getPointcut(AbstractAspectJAdvice.java:170)
                at org.springframework.aop.aspectj.AbstractAspectJAdv ice.buildSafePointcut(AbstractAspectJAdvice.java:1 80)
                at org.springframework.aop.aspectj.AspectJPointcutAdv isor.<init>(AspectJPointcutAdvisor.java:51)
                at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
                at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:85)
                at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:87)
                at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:186)
                at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:800)
                at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:720)
                at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:387)
                at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
                at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:156)
                at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
                at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:160)
                at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:287)
                at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:352)
                at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:91)
                at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:75)
                at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
                at com.w3electrical.sslines.examples.AopTesting.main( AopTesting.java:12)

                Comment


                • #9
                  Spring ships with asm 2.2.3. That should work with the jars you have.

                  Comment


                  • #10
                    Originally posted by Andreas Senft View Post
                    Spring ships with asm 2.2.3. That should work with the jars you have.
                    --
                    Yes, it was resolved. Thank you for the solution

                    Comment

                    Working...
                    X