Results 1 to 2 of 2

Thread: Problems with MethodBeforeAdvice

  1. #1
    Join Date
    May 2007
    Posts
    20

    Default Problems with MethodBeforeAdvice

    Hi,

    I have a problem with the MethodBeforeAdvise. I "registered" a class so all Method calls should be catched by an MethodBeforeAdvise-Implementation:

    Code:
    public class Logging implements MethodBeforeAdvice {
    	private Logging(){
    	}
    	public void before(Method method, Object[] args, Object target)throws Throwable{
    		System.out.println(method.getDeclaringClass() + ": " + method.getName());	
    	}
    }
    Heres the class which should be watched:

    Code:
    public class XDao implements IXDao{
       public ArrayList getAllX() {
          this.getX(0);
       }
    }
    public Mandant getX( Integer XId){
    }
    I simplified the classed so you dont get confused.

    And heres my applicationContext.xml:

    Code:
    <bean id="xDaoTarget" class="XDao"></bean>
    <bean id="theTracingAdvice" class="Logging" />
    <bean id="theTracingBeforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor" >
    		<property name="advice">
    			<ref local="theTracingAdvice" />
    		</property>	
    		<property name="pattern">
    			<value>.*</value>
    		</property>
    	</bean>
    <bean id="xDao"
    class="org.springframework.aop.framework.ProxyFactoryBean">	
    	<property name="proxyInterfaces">
    		<value>IXDao</value>
    	</property>	
    	<property name="target">
    		<ref local="xDaoTarget" />
    	</property>
    	<property name="interceptorNames">
    		<list>
    			<value>theTracingBeforeAdvisor</value>
    		</list>
    	</property>
    </bean>
    So actually all method calls should be catched by the Advice.
    This works fine when I call the getAllX()-Method (I get a print at the console). But the method called within the getAllX()-Method is not catched by the Advice.
    Does anyone know why this is so?

    Thanks in advance...

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    It is explained in the reference guide. Chapter 6 explains why it is. Especailly 6.6.1.

    Simply said only remote calls into the object are intercepted, internal calls (calls to this) are not being intercepted. If you need this you will need AspectJ and load- or compile time weaving.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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