Announcement Announcement Module
No announcement yet.
UnsatisfiedDependencyException when enabling AOP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • UnsatisfiedDependencyException when enabling AOP

    Novice problem.

    I have a working test app which, when AOP is configured, throws an error:

    Could not convert constructor argument value of type $Proxy10 to required type Account

    This has come up twice before in the archives but it isn't obvious what was fixed.

    Modified stack trace:
    UnsatisfiedDependencyException:Error creating bean with name User Unsatisfied dependency expressed through constructor argument of type Account Could not convert constructor argument value of type [$Proxy10] to required type Account

    Failed to convert value of type [$Proxy10 implementing org.springframework.beans.factory.DisposableBean,o rg.springframework.aop.SpringProxy,org.springframe work.aop.framework.Advised]to required type Account no matching editors or conversion strategy found

    I've tried various different things but it looks like my introduction of a wildcard PointCut (to log every method call in the app) has resulted in all the spring beans being converted to proxies - which is messing up the dependency injection.

    AOP Config is:
        <aop:include name="logAll"/>
    <bean id="logAll" class="com.self.aspects.LogAllMethods"/>

  • #2

    I've finally debugged the problem - by random trial & error.

    One of the spring beans implemented InitializingBean which I deleted, fixing the problem.

    What seemed to happen was it built a proxy rather than the spring bean which caused dependency injection problems (wrong type) and context.getBean problems (ClassCastException when cast).

    I've no idea why this worked - any offers welcome.


    • #3
      Spring AOP supports JDK- and CGLIB-based proxies - 6.1.3. AOP Proxies. The reference mentions algorithm of the desired proxying mechanism selection:
      GLIB is used by default if a business object does not implement an interface
      If the target object to be proxied implements at least one interface then a JDK dynamic proxy will be used. All of the interfaces implemented by the target type will be proxied. If the target object does not implement any interfaces then a CGLIB proxy will be created.
      You can force CGLIB usage - 6.6. Proxying mechanisms


      • #4
        Thanks - I'll have a play.

        From the above I need to force it to use CGLIB so it proxies the class not the interfaces it extends.