I'm not sure about the xfire-servlet mechanism, but when we first started
using Spring AOP with XFire + JSR-181 + Jsr181BeanPostProcessor, we found
that the Jsr181BeanPostProcessor was grabbing the service bean before the
AOP advice had been wrapped around it. Order is very important, since the
advice is applied at runtime to an object (by creating a proxy) - not to the
class, which is how many folks learn to use AOP. With Spring AOP, you can
easily have an object with and without the advice you've created, which
isn't the case with compile-time weaving.

xfire-servlet is either not looking at your Spring context bean at all (its
instantiating it purely from some configuration), or its grabbing your
Spring context bean before its been advised. I can't really tell w/o know
more about how xfire-servlet configuration works and what else you have in
your Spring context related to XFire.

Cheers,
Brice

On 12/31/06, yongguang zhao <[EMAIL PROTECTED]> wrote:

Hi,
I want to add some logging functionality to the XFire spring
example--Echo,
that is, after some client invokes the Echo service, I want to log
something.
I think Spring AOP is the best choice,
here is my applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd
">
<beans>
    <bean id="echoBean" class="org.codehaus.xfire.spring.example.EchoImpl
"/>
    <bean id="LoggingInterceptor" class="com.xyz.LoggingAdvice"/>

    <bean id="LoggingPointcutAdvisor" class="
org.springframework.aop.support.DefaultPointcutAdvisor ">
        <property name="advice">
            <ref local="LoggingInterceptor"/>
        </property>
        <property name="pointcut">
            <bean class="
org.springframework.aop.support.JdkRegexpMethodPointcut">
                <property name="pattern">
                    <value>.*</value>
                </property>
            </bean>
        </property>
 </bean>
 <bean id="LoggingAOPProxy" class="
org.springframework.aop.framework.ProxyFactoryBean">
  <property name="target">
   <ref local="echoBean" />
  </property>
  <property name="interceptorNames">
   <list>
    <value>LoggingPointcutAdvisor</value>
   </list>
  </property>
 </bean>
</beans>
the LoggingAdvice mentioned before is simple:

package com.xyz;

import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice ;

public class LoggingAdvice implements MethodBeforeAdvice,
AfterReturningAdvice {
 private static Log log = LogFactory.getLog(LoggingAdvice.class);

 public void before(Method method, Object[] args, Object target)
   throws Throwable {
  log.debug("before");
 }

 public void afterReturning(Object retuVal, Method method, Object[] args,
   Object target) throws Throwable {
  log.debug("afterReturning");
 }
}
while xfire-servlet.xml is the same as in the example.

However the interceptor just does not work,
can anyone please help me?

thanks.





--
Brice Ruth
Software Engineer, Madison WI

Reply via email to