Results 1 to 4 of 4

Thread: Spring @AspectJ Annotations not working, but schema based AOP support does???

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    Default Spring @AspectJ Annotations not working, but schema based AOP support does???

    Hello,

    I have created a simple Aspect which logs a method entry and method exit. I have managed to get it to work using schema based AOP support. However the same code does not execute when I change the configuration to use @AspectJ annotation support. Can anyone please explain where I am going wrong with my configuration?

    This configuration works:

    Code:
    <bean id="profiler" class="com.someCompany.someApp.logging.ProfilingAspect" />
    <aop:config>
         <aop:aspect ref="profiler">
              <aop:pointcut id="profileServiceMethods" expression="com.someCompany.someApp.SystemArchitecture.businessService()"/>
              <aop:around pointcut-ref="profileServiceMethods" method="profile"/>
         </aop:aspect>
    </aop:config>
    However, this configuration does not work:

    Code:
    <aop:aspectj-autoproxy/>
    <bean id="profiler" class="com.someCompany.someApp.logging.ProfilingAspect" />
    This is my Aspect code which logs the method entry/exit points:
    Code:
    package com.someCompany.someApp.logging;
    
    import org.apache.log4j.LogManager;
    import org.apache.log4j.Logger;
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    
    @Aspect
    public class ProfilingAspect {
    
    	@Around("com.someCompany.someApp.SystemArchitecture.businessService()")
        public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    	Logger log = LogManager.getLogger(pjp.getSignature().getDeclaringType());
        	long startTimeMillis = System.currentTimeMillis();
        	String methodName = pjp.getSignature().getName();
        	StringBuffer buffer = null;
        	if (log.isTraceEnabled()) {
        		buffer = new StringBuffer("Entering: [");
        		buffer.append(methodName).append("] id: [").append(startTimeMillis).append("]");
        		log.trace(buffer.toString());
        	}
    	try {
    		return pjp.proceed();
    	} finally {
    		long totalTimeMillis = System.currentTimeMillis() - startTimeMillis;
    		if (log.isTraceEnabled()) {
    			buffer = new StringBuffer("Exiting: [");
    	    		buffer.append(methodName).append("] id: [").append(startTimeMillis);
    	    		buffer.append("] total time: [").append(totalTimeMillis).append(" ms]");
    	    		log.trace(buffer.toString());
    		}
    	}
        }
    }
    This is my common point cut definition class:

    Code:
    package com.someCompany.someApp;
    
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    public class SystemArchitecture {
    
      @Pointcut("execution(* com.someCompany.someApp.service..*.*(..))")
      public void businessService() {}
    }
    Thanks in Advance
    Al

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    First

    Be sure that you have
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    However, this configuration does not work:
    <aop:aspectj-autoproxy/>
    Nothing happens or some error arise?

    comment your old configuration
    Code:
    <aop:config>
         <aop:aspect ref="profiler">
              <aop:pointcut id="profileServiceMethods" expression="com.someCompany.someApp.SystemArchitecture.businessService()"/>
              <aop:around pointcut-ref="profileServiceMethods" method="profile"/>
         </aop:aspect>
    </aop:config>
    Let me know your advance
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Apr 2009
    Posts
    2

    Default

    Hi dr_pompeii,

    My xsd was using version 2.0 for AOP, I have now changed this to 2.5, as per your suggestion, but I still cannot get it to work. I have not changed the code "ProfilingAspect" and "SystemArchitecture".

    This is the complete spring configuration I am using:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	   xmlns:context="http://www.springframework.org/schema/context"
    	   xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-2.5.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    	
    	<!-- Activates annotation-based bean configuration -->
    	<context:annotation-config />
    	
    	<!-- Scans for application @Components to deploy -->
    	<context:component-scan base-package="com.someCompany" />
    
    	<context:load-time-weaver/>
    	
    	<!-- This configuration does not work -->
    	<aop:aspectj-autoproxy/>
    	
    	<bean id="profiler" class="com.someCompany.someApp.logger.ProfilingAspect" />
    	
    	<!-- This commented out configuration works when not un-commented
    	<aop:config>
    		<aop:aspect ref="profiler">
    			<aop:pointcut id="profileServiceMethods" expression="com.someCompany.someApp.SystemArchitecture.businessService()"/>
    			<aop:around pointcut-ref="profileServiceMethods" method="profile"/>
    		</aop:aspect>
    		
    	</aop:config>
    	 -->
    </beans>
    This is my aop.xml:
    Code:
    <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
    	<weaver options="-verbose -showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
    		<!-- only weave classes in our application-specific packages -->
    		<include within="com.someCompany.someApp.*" />
    	</weaver>
    	<aspects>
    		<aspect name="com.someCompany.someApp.logger.ProfilingAspect" />
    	</aspects>
    </aspectj>
    This is a snippet of the working system out:
    Code:
    1422 [main] INFO weaving.DefaultContextLoadTimeWeaver  - Found Spring's JVM agent for instrumentation
    1719 [main] INFO AspectJ Weaver  - [AspectJ] AspectJ Weaver Version 1.6.1 built on Thursday Jul 3, 2008 at 18:35:41 GMT
    1719 [main] INFO AspectJ Weaver  - [AspectJ] register classloader org.apache.catalina.loader.WebappClassLoader@b0ce8f
    1719 [main] INFO AspectJ Weaver  - [AspectJ] using configuration /C:/eclipse-jee-ganymede-3-4/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/SomeApp/WEB-INF/classes/META-INF/aop.xml
    1766 [main] INFO AspectJ Weaver  - [AspectJ] register aspect com.someCompany.someApp.logger.ProfilingAspect
    2516 [main] INFO support.XmlWebApplicationContext  - Bean '(inner bean)' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2579 [main] INFO support.XmlWebApplicationContext  - Bean 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2579 [main] INFO support.XmlWebApplicationContext  - Bean '(inner bean)#2' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    This is a snippet of the not working system out:
    Code:
    1375 [main] INFO weaving.DefaultContextLoadTimeWeaver  - Found Spring's JVM agent for instrumentation
    1672 [main] INFO AspectJ Weaver  - [AspectJ] AspectJ Weaver Version 1.6.1 built on Thursday Jul 3, 2008 at 18:35:41 GMT
    1672 [main] INFO AspectJ Weaver  - [AspectJ] register classloader org.apache.catalina.loader.WebappClassLoader@b0ce8f
    1672 [main] INFO AspectJ Weaver  - [AspectJ] using configuration /C:/eclipse-jee-ganymede-3-4/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/SomeApp/WEB-INF/classes/META-INF/aop.xml
    1719 [main] INFO AspectJ Weaver  - [AspectJ] register aspect com.someCompany.someApp.logger.ProfilingAspect
    2859 [main] INFO support.XmlWebApplicationContext  - Bean '(inner bean)' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

    I notice the working version prints out this statement after weaving:
    Code:
    2579 [main] INFO support.XmlWebApplicationContext  - Bean 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    Thanks again.

  4. #4
    Join Date
    Jul 2009
    Posts
    2

    Default Need Code Full Code Pls

    Hi AL,

    could you please send me the whole code as a zip file (you can send to my mail id: sukkustudies@gmail.com). Am trying in both the ways(schema based as well as aspectJ), but not able to get the output. As you said, u able to get the o/p with schema based, pls send the code.

    Or else, ple tell me which calss should I run to get the output from your above code.

    Thanks,
    _Sukku.
    Last edited by sukku3234; Jul 22nd, 2009 at 06:52 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •