Announcement Announcement Module
Collapse
No announcement yet.
UnsatisfiedDependencyException when enabling AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
    <aop:aspectj-autoproxy>
        <aop:include name="logAll"/>
    </aop:aspectj-autoproxy>
    	
    <bean id="logAll" class="com.self.aspects.LogAllMethods"/>

  • #2
    Solution

    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.

    Comment


    • #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

      Comment


      • #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.

        Comment

        Working...
        X