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

  • Urgent help required in AOP

    Hi
    I have a nested packages in web application and we are using springs 2.0.6 and i am trying to apply my advice using springs AOP (as i can't use jdk > 1.4 ) to all packages
    my package structure is like this :
    com.
    com.abc.
    com.abc.xyz.
    com.abc.efg.
    com.abc.efg.asd.
    and so on....

    springsaopconfiguration.xml


    Code:
    <bean id="Logger1" class="com.abc.xyz.AopLogger">
    <aop:config>
    		<aop:aspect ref="Logger1">
    			<aop:after method="after"
    			pointcut="execution(* com..abc.cdf..*.*(..))"/>
    			<aop:before method="before"
    			pointcut="execution(* com..abc.cdf..*.*(..))"/>
    		</aop:aspect>
    </aop:config>
    AopLogger.java
    Code:
    mport org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.apache.log4j.Logger;
    import org.aspectj.lang.ProceedingJoinPoint;
    
    public class AopLogger {
    	private static String indent = ""; 
    	public void after(ProceedingJoinPoint call) throws Throwable {
    		System.out.print("After");
    		System.out.print(" - METHOD : "+call.toShortString());
    	}
    
    	public void before(ProceedingJoinPoint call) throws Throwable {
    		System.out.print("Before");
    			}
    
    }
    but when i run the application it give out put

    Before
    Before
    Before
    Before
    and then


    Exception in thread "main" java.lang.StackOverflowError.

    org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethodWithGivenArgs(AbstractAspect JAdvice.java:576)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethod(AbstractAspectJAdvice.java: 555)
    at org.springframework.aop.aspectj.AspectJMethodBefor eAdvice.before(AspectJMethodBeforeAdvice.java:39)
    at org.springframework.aop.framework.adapter.MethodBe foreAdviceInterceptor.invoke(MethodBeforeAdviceInt erceptor.java:49)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:89)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:630)
    at com.hsbc.b2g.csa.example.aop.AdviceOne$$EnhancerBy CGLIB$$8175769f.after(<generated>)
    at sun.reflect.GeneratedMethodAccessor6.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethodWithGivenArgs(AbstractAspect JAdvice.java:576)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethod(AbstractAspectJAdvice.java: 555)
    at org.springframework.aop.aspectj.AspectJAfterAdvice .invoke(AspectJAfterAdvice.java:45)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:89)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:630)
    at com.hsbc.b2g.csa.example.aop.AdviceOne$$EnhancerBy CGLIB$$8175769f.after(<generated>)
    at sun.reflect.GeneratedMethodAccessor6.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethodWithGivenArgs(AbstractAspect JAdvice.java:576)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethod(AbstractAspectJAdvice.java: 555)
    at org.springframework.aop.aspectj.AspectJAfterAdvice .invoke(AspectJAfterAdvice.java:45)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:89)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:630)
    at com.hsbc.b2g.csa.example.aop.AdviceOne$$EnhancerBy CGLIB$$8175769f.before(<generated>)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethodWithGivenArgs(AbstractAspect JAdvice.java:576)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethod(AbstractAspectJAdvice.java: 555)
    at org.springframework.aop.aspectj.AspectJMethodBefor eAdvice.before(AspectJMethodBeforeAdvice.java:39)
    at org.springframework.aop.framework.adapter.MethodBe foreAdviceInterceptor.invoke(MethodBeforeAdviceInt erceptor.java:49)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:89)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :166)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:630)
    at com.hsbc.b2g.csa.example.aop.AdviceOne$$EnhancerBy CGLIB$$8175769f.after(<generated>)
    at sun.reflect.GeneratedMethodAccessor6.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethodWithGivenArgs(AbstractAspect JAdvice.java:576)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethod(AbstractAspectJAdvice.java: 555)
    at org.springframework.aop.aspectj.AspectJAfterAdvice .invoke(AspectJAfterAdvice.java:45)


    and so on

    but when i run advice with only before or after it works fine ...
    can any one help me
    where i am going wrong
    Last edited by gaganjava; Jun 4th, 2008, 06:33 AM.

  • #2
    Have you tried around advice? This saves having both before and after config....

    Comment


    • #3
      aop

      Hi, i can't use the around advice .....

      Comment


      • #4
        Originally posted by gaganjava
        Hi, i can't use the around advice .....
        Why not? If you can use before and after you can surely use the around one....

        Also your pointcut has a problem and you probably also intercept calls to the interceptor itself, resulting in the stackoverflow.

        Comment


        • #5
          maybe can not nested packages in web application

          Comment


          • #6
            regarding injecting interface in aop based application

            hi as i am new to springs aop .

            my advice is as follows;

            Code:
            package com.hsbc.b2g.csa.example.aop;
            
            
            import org.aspectj.lang.ProceedingJoinPoint;
            
            public class AroundLogger {
            	
            	public Object log(ProceedingJoinPoint call) throws Throwable
            	{
            		System.out.println("BEFORE Method Invocation");
            		
            		Object obj = call.proceed();
            		
            		System.out.print("AFTER Method Invocation");
            		
            		return null;
            	}
            	
            
            }

            my springaop configuration is as follows.
            Code:
            <aop:config>
            		<aop:aspect ref="Logger3">
            			<aop:pointcut id="point" expression="execution(* *(..))"/>	
            				<aop:around method="log" pointcut-ref="point"/>	
            		</aop:aspect>	
            	</aop:config>
            in my configuration i have one class InterClass which implements one interface Inter and one factory class(i am using BeanFactoryAware and FactoryBean) which return the object of InterClass.
            when i am trying to inject that interface in another class it gives me error as follows....................
            init called
            BEFORE Method Invocation
            AFTER Method Invocation- Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@ba20ba2: defining beans [CSA_Configuration_Manager,DefaultIDVServiceWrapper ,IDVServiceWrapper,bbc,cc,ecc,fb,fmarc,gf,nch,lc,c lp,bbp,crcp,sep,testc,rc,fir,su,ehu,gvb,upu,ri,Mov ieLister,ColonMovieFinder,MemoryMovieFinder,dsa,ab c,test,test1,test2,MapMovieFinder,Logger,Logger1,L ogger2,Logger3,org.springframework.aop.config.inte rnalAutoProxyCreator,org.springframework.aop.aspec tj.AspectJPointcutAdvisor,point]; root of factory hierarchy
            Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'clp' defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
            Caused by: java.lang.NullPointerException
            at $Proxy2.isSingleton(Unknown Source)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getObjectForBeanInstance(AbstractBeanF actory.java:1203)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:208)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:160)
            at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:261)
            at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:109)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1099)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:861)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:421)
            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 com.hsbc.b2g.csa.example.main.Main.main(Main.java: 53)
            so can any one tell me whats problem ...

            Thanks in Advance .............

            Comment


            • #7
              In your around advice you are modifying your original method calls you NEVER return anything. Which means EVERY method returns NULL.

              Please use [ code][/code ] tags around stacktraces also.

              Code:
              public Object log(ProceedingJoinPoint call) throws Throwable {
              	System.out.println("BEFORE Method Invocation");
              	Object obj = call.proceed();
              	System.out.print("AFTER Method Invocation");
              	return null;
              }
              The red part should return the result of your call to proceed...

              Code:
              public Object log(ProceedingJoinPoint call) throws Throwable {
              	System.out.println("BEFORE Method Invocation");
              	Object obj = call.proceed();
              	System.out.print("AFTER Method Invocation");
              	return obj;
              }

              Comment


              • #8
                advice stops application

                hi ,

                my advice only is works for my factorybeans after that it stops the application what may be the problem or where i am wrong .
                my all beans are created through springs. accept my logger class its fianl class with static methods.

                thanks in advance.

                Comment


                • #9
                  "after that it stops the application"??????

                  Stack trace???

                  Comment


                  • #10
                    advice not working on some functions.

                    hi , my advice is working fine now. buti have another problem with it. That is if a function is called by another function in the same class my advice is not implmented on that called function. can any one answer where i am wrong.
                    Thanks in Advance.
                    Last edited by gaganjava; Jun 19th, 2008, 08:27 AM. Reason: mistakes

                    Comment


                    • #11
                      Which is how proxy based AOP works. Chapter 6.6.1 of the reference guide explains this. Only method calls passing through the proxy are going to be intercepted. If you want something else you will need a full blown AOP solution, like AspectJ together with loadtime or compiletime weaving.

                      Comment

                      Working...
                      X