Announcement Announcement Module
Collapse
No announcement yet.
Question about MethodBeforeAdvice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about MethodBeforeAdvice

    Dear all,

    I wanted to add MethodBeforeAdvice for logging in my web application. I added it in this way:
    <bean id="logBeforeAdvisor" class="xxx.LogBeforeAdvisor" >
    ......
    </bean>

    <bean id="logBeforeRegExpAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="patterns">
    <list>
    .....
    </list>
    </property>
    <property name="advice">
    <ref bean="logBeforeAdvisor"/>
    </property>
    </bean>

    <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator" />

    For the class, it defined it in this way:
    public class LogBeforeAdvisor implements MethodBeforeAdvice,ApplicationContextAware {
    ....
    }

    Since its usage is logging, i need to be able to get the http request in my LogBeforeAdvisor class. I would like to know how i can get the request in my class? can i get it from the applicationContext? or i need to implement some other interface to make it work? or is there any bean i need to inject into my LogBeforeAdvisor to make it work?

    Thank you!
    Last edited by da01661; Mar 16th, 2008, 09:10 PM.

  • #2
    anybody got idea?

    thanks!

    Comment


    • #3
      Hey i thing you can use the Method Interceptor for Logger Application using the Method Interceptor ... Below is little sample that might help you

      public class MethodDecorator implements MethodInterceptor {


      public Object invoke(MethodInvocation methodInvocation) throws Throwable {

      System.out.println("Before Around Adivce Method Is Implemented "+methodInvocation.getMethod());
      Object retval=methodInvocation.proceed();
      System.out.println("After Around Adivce Method Is Implemented " +methodInvocation.getMethod());
      return retval;
      }

      }

      In the XMl file ,
      <bean id="methodDecorator" class="MethodDecorator" />

      <bean id="proxyTargetClass" class="org.springframework.aop.framework.ProxyFact oryBean">
      <property name="proxyInterfaces" value="ITarget" />
      <property name="interceptorNames">
      <list>
      <value>methodDecorator</value>
      </list>
      </property>

      <property name="target" ref="ItargetImpl" />
      </bean>



      <bean id="ItargetImpl" class="Target" />

      Comment

      Working...
      X