Announcement Announcement Module
Collapse
No announcement yet.
Dependency Issues while using AOP for logging Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dependency Issues while using AOP for logging

    Hello,

    I have implemented logging using AOP point cuts definitions. The point cuts have been applied at a package level , so that when any method gets executed within all the classes in a specific package , the point cuts needs to be executed.

    The following is the corresponding section in my bean definition XML
    Code:
    <aop:config>
    		<aop:pointcut id="servicePointcut"
    			expression="execution(* com.examples.myapplication.bo.*.*(..))" />
    		<aop:aspect id="loggingAspect" ref="methodLogger">
    			<aop:before method="logEntry"
    				pointcut-ref="servicePointcut" />
    			<aop:after-returning method="logExit"
    				pointcut-ref="servicePointcut" />
    			<aop:after-throwing method="logException"
    				pointcut-ref="servicePointcut" throwing="exception" />
    		</aop:aspect>
    	</aop:config>
    
    
    
    	<aop:config>
    		<aop:pointcut id="DAOPointcut"
    			expression="execution(* com.examples.myapplication.dao.*.*(..))" />
    		<aop:aspect id="DAOLoggingAspect" ref="methodLogger">
    			<aop:before method="logEntry"
    				pointcut-ref="DAOPointcut" />
    			<aop:after-returning method="logExit"
    				pointcut-ref="DAOPointcut" />
    			<aop:after-throwing method="logException"
    				pointcut-ref="DAOPointcut" throwing="exception" />
    		</aop:aspect>
    	</aop:config>

    The issue is that most of the beans defined for the classes under the package com.examples.myapplication.bo contain classes under the other package com.examples.myapplication.dao as their member variables. As point cuts have been defined for both the packages , when the beans are getting intialized , an configuration exception is thrown during the startup.

    Following is one such bean definition which involves classes from the above packages.

    Code:
    <bean id="companyBO"
    		class="com.examples.myapplication.bo.CompanyBO">
    		<constructor-arg index="0">
    			<ref bean="companyDAO" />
    
    
    <bean id="companyDAO"
    		class="com.examples.myapplication.dao.CompanyDAO"/>
    The exception which is thrown during the startup is as follows
    Unsatisfied dependency expressed through constructor argument with index 0 of type [com.examples.myapplication.dao.CompanyDAO]: Could not convert constructor argument value of type [$Proxy4] to required type [com.examples.myapplication.dao.CompanyDAO]: Failed to convert value of type [$Proxy4] to required type [com.examples.myapplication.dao.CompanyDAO]; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4] to required type [com.examples.myapplication.dao.CompanyDAO]: no matching editors or conversion strategy found
    .

    As point cuts are defined for both the packages , I suspect the Proxy created is getting assigned rather than the actual class at run time.

    Any leads in this regard would be really helpful.

    Thanks a lot in Advance.

    Cheers
    Thiag

  • #2
    one way to "fix" this is to declare

    Code:
    <aop:aspectj-autoproxy proxy-target-class="true" />
    and use class proxying. the other one would be to revisit your packaging as it seems a bit odd that your service pointcut does not contain .service package anywhere which may look for the outsiders as a packaging problem...

    Comment

    Working...
    X