3 Replies Latest reply on Jan 4, 2007 10:42 AM by 807607

    Spring Question,  My Advice class is not being used

    807607
      I am getting a proxy to myBean from the factory using the id "MyBeanProxyWithMethodMatchingPattern".
      This Proxy is created using an "advisor".
      This advisor is created using a MyAdvice instance and a PointCut instance which has a pattern matching on all methods starting with e*
      Problem is (1)my advice does not get applied to the methods and (2) the pointCut pattern does not seem to be working either. I have taken this example from the Pro Spring Book.
      I have no problem with using Springs own Interceptors but I want to be able to build my own. I have the same problem getting advisors to work when I hard code them in my java code and don't bother using Springs AOP framework.
      Any ideas what I'm missing?
      public class Driver
      {
           
           public static void main(String[] args)
           {
                ApplicationContext ac = 
                     new FileSystemXmlApplicationContext("applicationcontext.xml");
                MyBeanInt bean1 = (MyBeanInt) ac.getBean("MyBeanProxyWithMethodMatchingPattern");
                bean1.execute();
                bean1.doit();
           }
      }
      
      ***********************
      
      public class MyAdvice implements MethodBeforeAdvice
      {
      
           /**
            *
            */
      
           public void before(Method method, Object[] args, Object target)
                     throws Throwable
           {
                
                System.out.println(">>>" + method.getName() + "()");
           }
      
      }
      
      ********************
      
      public class MyBean implements MyBeanInt
      {
           public void execute()
           {
                System.out.println("execute doing stuff");
           }
           
           public void doit()
           {
                System.out.println("doit doing stuff");
           }
      }
      
      *************************
      
      public interface MyBeanInt
      {
           public abstract void execute();
      
           public abstract void doit();
      }
      ***********************
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
      
      <beans>
      
           <bean      id="MyBeanProxyWithMethodMatchingPattern" 
                     class="org.springframework.aop.framework.ProxyFactoryBean" >     
                <property name="target">
                     <ref local="MyTarget">
                     </ref>
                </property>
                <property name="interceptorNames">
                     <list>
                          <value>advisor</value>
                     </list>
                </property>          
           </bean>     
           
           <bean id="MyTarget" class="MyBean" >     
           </bean>
           
           <bean      id="advice" class="MyAdvice" >
           </bean>
           
           <bean      id="advisor" 
                     class="org.springframework.aop.support.DefaultPointcutAdvisor" >
                <property name="advice">
                     <ref local="advice"/>
                </property>
                <property name="pointcut">
                     <bean class="org.springframework.aop.support.JdkRegexpMethodPointcut">
                          <property name="pattern">
                               <value>e*</value>
                          </property>
                     </bean>
                </property>          
           </bean>
           
      </beans>