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

  • Logging and AOP

    I am a newbie to AOP. I am trying to implement trace logging, where I would like to log the entry and exit of every method.

    for that i have written

    @Aspect
    public class TraceLoggingAspect {

    TraceLogger logger;

    public TraceLoggingAspect()
    {
    logger=new TraceLogger();
    }

    @Pointcut("execution(* *(..))")
    public void eachMethod(){}

    @Around("eachMethod()")
    public void log(ProceedingJoinPoint joinpoint)
    {
    String logID=System.nanoTime()+"";
    logger.debug(logID, "Entering method.."+joinpoint.getSignature());


    try
    {
    joinpoint.proceed();
    logger.debug(logID, "Exiting method.."+joinpoint.getSignature());
    }
    catch (Throwable e)
    {
    logger.error(logID, e.getMessage(),e);
    }


    }
    }


    and have used <aop:aspectj-autoproxy/> in my appliaction-config.xml to create auto proxy.

    Nothing is getting logged into the trace file. I might be missing something very basic...can someone throw light.

  • #2
    Actually, I didnt declare the bean definition for the aspect.

    So now I added the following bean definition to my config file...
    <aop:aspectj-autoproxy/>

    <bean name="traceLoggingAspect" class="com.bcbsnc.rdb.logging.TraceLoggingAspect"/>

    Now , I run into a different issue...

    org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'sessionFactory': Bean with name 'sessionFactory' has been injected into other beans [transactionManager] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:431)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 49)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:155)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:246)


    and these are the bean definitions

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="rdbDataSource" />
    <property name="mappingLocations">
    <list>
    <value>classpath:com/bcbsnc/rdb/model/ModelEntities.hb.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>hibernate.format_sql=true</value>
    </property>
    </bean>


    <bean id="rdbDataSource" class="com.ibm.db2.jcc.DB2SimpleDataSource" destroy-method="close" lazy-init="true">
    <property name="serverName" value="192.168.5.9" />
    <property name="portNumber" value="50000" />
    <property name="databaseName" value="RNCDU01" />
    <property name="cliSchema" value="RDB" />
    <property name="user" value="db2admin" />
    <property name="password" value="itpc" />
    <property name="currentSchema" value="RDB" />
    <property name="driverType" value="4" />
    </bean>

    <!-- Instructs the container to look for beans with @Transactional and decorate them -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- A transaction manager for working with Hibernate SessionFactories -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>


    Please help....

    Comment


    • #3
      If i remove the apsectj configuration from the configuration file..i dont get the error.

      Looks like there is an issue with the annotation based use of aop and transactions.... can anyone help

      Comment


      • #4
        You can also refer to the logging example featured in Mark Fisher's Blog

        -Nikhil

        Comment

        Working...
        X