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

  • Logging help

    Hi,
    I am trying to implement logging in my project. I have used example from
    http://www.devx.com/Java/Article/30799/0/page/2 but it is not working. Application works fine and does not throw any exception. But the logging is not happenig
    I have carefully read some tutorials but I am not able to solve this problem.

    Can someone tell me where am I wrong?

    Here are my code snippets
    applicationContext.xml
    Code:
    <bean id="AbcServiceBean" class="org.springframework.aop.framework.ProxyFactoryBean">
    			              <property name="proxyInterfaces">
                              	<value>com.logic.GenericDAO</value>
                              </property>
    		<property name="target">
    			<ref bean="AbcDAO"/>
    		</property>
    		<property name="interceptorNames">
    			<list>				
    				<value>loggingInterceptor</value>
    			</list>
    		</property>		
    </bean>	
    
    <bean id="AbcDAO" class="com.logic.AbcDAO">
    	<property name="sessionFactory"><ref bean="hibernateSessionFactory" /></property>
    </bean>
    <bean id="loggingInterceptor"  class="com.web.LoggingInterceptor"/>	
    </beans>
    AbcDAO
    Code:
    public class AbcDAO extends HibernateDaoSupport implements GenericDAO {
    
    .....
    ....
    some business methods
    ....
    ....
    
    }
    GenericDAO

    Code:
    public interface GenericDAO {
    
    }
    Logging interceptor it is basically exactly the same as given in the tutorial
    Code:
    public class LoggingInterceptor implements MethodBeforeAdvice,
            AfterReturningAdvice, ThrowsAdvice {
        private static Logger log = null;
        public LoggingInterceptor(){
        }
        
        public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable {
            log = Logger.getLogger(arg2.getClass());
            log.info("Beginning method: "+arg0.getName());
        }
        
        public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable {     
            log = Logger.getLogger(arg3.getClass());
            log.info("Ending method: "+arg1.getName());     
        }
        
        public void afterThrowing(Method m, Object[] args, Object target, Throwable ex) 
        { 
            log = Logger.getLogger(target.getClass());
            log.info("Exception in method: "+m.getName()+" Exception is: "+ex.getMessage());    
        }
    
    }
    Last edited by parasjain01; Jun 15th, 2007, 10:21 AM. Reason: [code] tags

  • #2
    Am I right that GenericDAO interface doesn't have any method? In this case LoggingInterceptor will intercept nothing...

    Comment


    • #3
      GenericDAO updated

      Even when I update the interface to

      Code:
      public Map enroll(AbcUser abcUser);
      it is not working.

      When the enroll method of AbcDAO is called then the logging module is not hit.

      Comment


      • #4
        Is it possible to see the code you are using to test this? There are a couple of common causes for this, #1 you are creating your bean using the new operator instead of looking it up, #2 you are looking up the wrong bean, instead of looking up the proxy e.g. 'AbcServiceBean' you are looking up 'AbcDAO'.
        Last edited by karldmoore; Aug 29th, 2007, 11:45 AM.

        Comment


        • #5
          Yes that may be the cause

          You guys are great. Probably here I am making some mistake. But I don't know how to correct it because I have not much experience in Spring. We use Spring just for little bit IoC etc

          I cannot put the full code here. But I am doing something like this
          Code:
          AbcDAO dao = (AbcDAO) webCtx.getBean("AbcDAO");
          I think I should do something like
          Code:
          (ProxyFactoryBean)webCtx.getBean("AbcServiceBean")
          But then how to extract AbcDao from it?

          Comment


          • #6
            Can you try
            Code:
            GenericDAO dao = (GenericDAO) webCtx.getBean("AbcServiceBean");
            System.out.println( dao.enroll( <some your user instance> ) );

            Comment


            • #7
              The code you've posted is correct, but the cast is actually to the type rather than the proxy. If you were programming to interfaces then you could simply cast to that type, if you're not then you need to set proxyTargetClass="true" on ProxyFactoryBean and cast to the concrete type.
              http://www.springframework.org/docs/...l#aop-proxying
              Last edited by karldmoore; Aug 29th, 2007, 11:45 AM.

              Comment


              • #8
                Its working

                Thanks a ton to karldmoore and mpetrashev

                Comment


                • #9
                  Is the code in side one spring controller?

                  Originally posted by parasjain01 View Post
                  You guys are great. Probably here I am making some mistake. But I don't know how to correct it because I have not much experience in Spring. We use Spring just for little bit IoC etc

                  I cannot put the full code here. But I am doing something like this
                  Code:
                  AbcDAO dao = (AbcDAO) webCtx.getBean("AbcDAO");
                  I think I should do something like
                  Code:
                  (ProxyFactoryBean)webCtx.getBean("AbcServiceBean")
                  But then how to extract AbcDao from it?
                  Hello, I am also new in Spring AOP, I just wanna ask is the code
                  Code:
                  AbcDAO dao = (AbcDAO) webCtx.getBean("AbcDAO");
                  and
                  Code:
                  (ProxyFactoryBean)webCtx.getBean("AbcServiceBean")
                  in a controller in order to get the logging info for a application??? Or my question is where I should put the above two code in my spring application in order to get the logging infor?? Where I should active the logging task, how to active? by call a URL which mapped to a controller, then controller active the logging event or what?Thanks

                  Comment


                  • #10
                    Originally posted by blust1984 View Post
                    in a controller in order to get the logging info for a application??? Or my question is where I should put the above two code in my spring application in order to get the logging infor?? Where I should active the logging task, how to active? by call a URL which mapped to a controller, then controller active the logging event or what?Thanks
                    I'm not exactly sure about the question. Any chance you can explain a little more about what you're not sure about?
                    Last edited by karldmoore; Aug 29th, 2007, 11:45 AM.

                    Comment

                    Working...
                    X