Results 1 to 5 of 5

Thread: unable to proxy using BeanNameAutoProxyCreator

  1. #1

    Default 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is it possible to see the rest of the code you are using to run this?
    Last edited by karldmoore; Aug 27th, 2007 at 04:10 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default

    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.

  4. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    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

  5. #5

    Default

    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

Posting Permissions

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