Results 1 to 4 of 4

Thread: UnsatisfiedDependencyException when enabling AOP

  1. #1
    Join Date
    Nov 2008
    Location
    Reading, England
    Posts
    20

    Default 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. #2
    Join Date
    Nov 2008
    Location
    Reading, England
    Posts
    20

    Default 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.

  3. #3
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    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. #4
    Join Date
    Nov 2008
    Location
    Reading, England
    Posts
    20

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •