Results 1 to 8 of 8

Thread: AOP type conversion error

  1. #1

    Default AOP type conversion error

    I am trying to use AOP to profile some of the work I am doing. This question is answered quite a few times in this forum but answers doesn't really fit in my situation.

    I have a ConcreteClass that extends an abstract class which in-turn implements an interface. I am trying to write an around advice on a method in the ConcreteClass. Here is my ConcreteClass bean definition with pointcut expression I am using

    Code:
         <bean id="concreteClass" class="com.mycompany.ConcreteClass"/>
        @Pointcut("execution(* com.mycompany.ConcreteClass.run())")
    Now running this through is causes exception

    Code:
    Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy56 implementing com.mycompany.SomeInterface,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.mycompany.ConcreteClass] for property 'concreteClass': no matching editors or conversion strategy found
    Some of the threads in the forum suggested doing this

    Code:
    proxy-target-class="true"
    Now I don't want to change the proxy setting which causes rest of the application to fail.

    Any suggestions?

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

    Default

    Your problem is described here. Spring AOP is proxy-based and it allows to use only jdk- or cglib-proxies, so, if you want to use spring aop and can't use jdk proxies, your only way is to use cglib proxies.

    Another approach is to use aspectj weaving.

  3. #3

    Default Re: AOP type conversion error

    Thanks Denis...

    I understand that I need to use class based proxy to advice a class that implements an interface. But what I fail to understand is why? Also it means that rest of the application that is using the default proxy setting (jdk proxy) needs re-factoring to use class based proxy; else use aspectj weaving.

    Isn't @Transactional use proxy to apply transactional demarcation? For example if I have a class annotated with @Transactional that implements an interface and I have not changed the default proxy setting. How does this work then?

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

    Default

    Quote Originally Posted by parmod View Post
    Thanks Denis...

    I understand that I need to use class based proxy to advice a class that implements an interface. But what I fail to understand is why?
    So, you read the blog entry I mentioned before and there is still no understanding of the problem cause?


    Quote Originally Posted by parmod View Post
    Also it means that rest of the application that is using the default proxy setting (jdk proxy) needs re-factoring to use class based proxy; else use aspectj weaving.
    The only problem I see with cglib-proxying is that you can't advice classes without no-args constructor and final classes.


    Quote Originally Posted by parmod View Post
    Isn't @Transactional use proxy to apply transactional demarcation? For example if I have a class annotated with @Transactional that implements an interface and I have not changed the default proxy setting. How does this work then?
    It works at the Spring AOP then - aop-aware proxy is returned by container instead of 'raw' bean.

  5. #5

    Default

    Quote Originally Posted by denis.zhdanov View Post
    So, you read the blog entry I mentioned before and there is still no understanding of the problem cause?
    I did understand the problem cause denise. I actually did know when I first ran into this problem but I guess I needed a confirmation.

    Quote Originally Posted by denis.zhdanov View Post
    It works at the Spring AOP then - aop-aware proxy is returned by container instead of 'raw' bean.
    So container takes care of this? But container can't in case of general AOP advice?

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

    Default

    Quote Originally Posted by parmod View Post
    So container takes care of this? But container can't in case of general AOP advice?
    The question is unclear. What do you mean under 'general AOP advice'?

    Spring AOP has particular limitations due to its proxy-based nature. The most significant from them are (imho) self-calls, vague proxying mechanism selection algorithm and inability to use cglib proxying for the classes without no-args ctor.

  7. #7

    Default

    Quote Originally Posted by denis.zhdanov View Post
    The question is unclear. What do you mean under 'general AOP advice'?

    Spring AOP has particular limitations due to its proxy-based nature. The most significant from them are (imho) self-calls, vague proxying mechanism selection algorithm and inability to use cglib proxying for the classes without no-args ctor.
    Denis all I was saying is if Spring returns aop-aware bean for transaction annotated bean instead of 'raw' bean. Why can't Spring return aop-aware bean for other advices? (like around advice etc. etc.)

    Like in my example class with an interface can't be proxied using jdk proxies however class with an interface using transactional annotation can be proxied.

    I guess problem may be I don't fully understand Spring proxy implementation

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

    Default

    Quote Originally Posted by parmod View Post
    Denis all I was saying is if Spring returns aop-aware bean for transaction annotated bean instead of 'raw' bean. Why can't Spring return aop-aware bean for other advices? (like around advice etc. etc.)
    Spring transactions are built on the top of spring aop. I.e. spring uses the same mechanisms either for implementing transaction behavior or applying other aspects.


    Quote Originally Posted by parmod View Post
    Like in my example class with an interface can't be proxied using jdk proxies however class with an interface using transactional annotation can be proxied.

    I guess problem may be I don't fully understand Spring proxy implementation
    You can use jdk proxies with class that implements interfaces. You're not allowed to cast the proxy to concrete class then.

Posting Permissions

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