Results 1 to 3 of 3

Thread: Simple AOP Example

  1. #1
    Join Date
    Dec 2006
    Posts
    311

    Default Simple AOP Example

    Hello all,

    I think I am close to hacking together a really simple AOP example but its not quite working. Here is my aspect class:

    Code:
    @Aspect
    public class SystemArchitecture {
    
      @Pointcut("execution(public * *(..))")
      public void businessService() {
    	  System.out.println("Hello World!");
    	  
      }
    
    }

    In my XML file:

    Code:
        <aop:aspectj-autoproxy/>
        <bean id="systemArchitecture " class="aop.SystemArchitecture"/>
         
        <bean id="service" class="service.ServiceImp" />
       
        
        <bean id="springappController" class="web.SpringappController">
            <property name="commandName"><value>command</value></property>
            <property name="commandClass"><value>command.HelloCommand</value></property>    
            <property name="formView"><value>hello.jsp</value></property>
            <property name="successView"><value>hello.jsp</value></property> 	
            <property name="service">
            	<ref bean ="service"/>
            </property>	        
        </bean>


    In my controller I have a call to a method in the service.Service class called sayHello.

    The small app is building and deploying fine but the pointcut method is not firing even though I thought it should for ANY pulic method because of this line:

    @Pointcut("execution(public * *(..))")


    What am I missing? I figure its something in the XML file.

    I pretty much took the examples in the documentation and hacked it into a small web app. Any ideas?

  2. #2
    Join Date
    Oct 2004
    Location
    Fareham, England
    Posts
    313

    Default

    Hi

    The advice logic needs to go in another method, and that method needs to reference the pointcut and say what 'type' of advice you want (after-returning, around, before, etc.).

    For example:

    Code:
    @Aspect
    public class SystemArchitecture {
    
      @Pointcut("execution(public * *(..))")
      public void businessService() {}
    
      @Before("businessService()")
      public void sayHello() {
        System.out.println("Hello World!");
      }
    }
    Cheers
    Rick

  3. #3
    Join Date
    Dec 2006
    Posts
    311

    Default

    Thank you,

    Is any configuration in the xml files needed with spring 2.0? From what I gather from the docs you can either use annotation or configure things in xml. In my simple example is anything for aop needed in the xml file?

Posting Permissions

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