Announcement Announcement Module
Collapse
No announcement yet.
unable to proxy using BeanNameAutoProxyCreator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • unable to proxy using BeanNameAutoProxyCreator

    I am trying to log the start, end and time taken to execute each method. I have the following in applicationContext.xml

    Code:
    <bean id="managerProxyCreator"	
    	class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            <property name="beanNames"><value>*Image*</value></property>
    	<property name="proxyTargetClass"><value>true</value></property>
            <property name="interceptorNames">
                <list>
                    <value>myInterceptor</value>
    		<value>loggingInterceptor</value>
                </list>
            </property>
        </bean>
    
    <bean id="myInterceptor" class="com.company.interceptor.MyInterceptor" />
        <bean id="loggingInterceptor" class="org.springframework.aop.interceptor.SimpleTraceInterceptor"/>
    
    <bean id="hibImage"	class="com.company.grayline.image.HibImageImpl">
            <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>
    MyInterceptor code looks like this

    Code:
    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class MyInterceptor implements MethodInterceptor {
        private final Log logger = LogFactory.getLog("MAIN");
    
        public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    	
    	if(logger.isInfoEnabled()){
    	    logger.info("********Beginning method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName());
    	}
    	long startTime = System.currentTimeMillis();
    	try {
    	    Object retVal = methodInvocation.proceed();
    	    return retVal;
    	} finally {
    	    if(logger.isInfoEnabled()){
    		logger.info(">>>>>>>>>>>>>Method invocation time: " + (System.currentTimeMillis() - startTime) + " msecs.");
    		logger.info("##########Ending method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName());
    	    }
    	}
        }
    
    }
    it does not log anything. Can anyone point out what is that I am doing wrong.

    Thanks

  • #2
    Is it possible to see the rest of the code you are using to run this?
    Last edited by karldmoore; Aug 27th, 2007, 04:10 PM.

    Comment


    • #3
      I am not sure what other code to provide. is there any thing specific that you want to take a look, like web.xml etc.

      Comment


      • #4
        What type of object is HibImageImpl for example to which the interceptors should be applied? How do you retrieve it from the application context? It's suspicious when Hibernate is involved as it seems since Hibernate creates its own proxies which also might wipe out your interceptors.

        Jörg

        Comment


        • #5
          this is my hibImageImpl code

          Code:
          package com.company.image;
          
          import com.company.model.Images;
          import java.util.List;
          import java.util.ArrayList;
          
          import org.apache.log4j.Logger;
          import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
          
          public class HibImageImpl extends HibernateDaoSupport implements ImageIntf {
              protected Logger log = Logger.getLogger("MAIN");
              Images img;
          
              public HibImageImpl() {
              }
          
              public List<Images> getHeaderImage() {
          	List l = getHibernateTemplate().findByNamedQuery("header.image");
          	log.info("retrieved images from db. size of resultset = " + l.size());
          	List<Images> imgList = new ArrayList<Images>();
          	for (int i = 0; i < l.size(); i++) {
          	    Object[] row = (Object[])l.get(i);
          	    img = new Images();
          	    img.setImagePath((String)row[0]);
          	    img.setDescription((String)row[1]);
          
          	    imgList.add(img);
          	}
          	return imgList;
              }
          
              public void setImg(Images img) {
          	this.img = img;
              }
          }
          Thanks for all the help

          Comment

          Working...
          X