Spring Framework
  1. Spring Framework
  2. SPR-8813

AutowiredAnnotationBeanPostProcessor CGLIB proxies

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.0.5
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      AutowiredAnnotationBeanPostProcessor.buildAutowiringMetadata does not find method annotations on CGLIB proxies

      problem occurs when using custom valueResolver and calling beanFactory.autowireBeanProperties after first context initialization

      solution would be using ClassUtils.getUserClass in method AutowiredAnnotationBeanPostProcessor.findAutowiringMetadata

        Activity

        Hide
        Chris Beams added a comment -

        Hi Madis,

        This certainly makes sense and we'll look into it. Could you quickly verify the behavior against 3.1.0.RC1 or 3.1.0.BUILD-SNAPSHOT as well?

        It would also be useful if you could add a simple test case or reproduction project per https://github.com/SpringSource/spring-framework-issues#readme

        Thanks,

        Chris

        Show
        Chris Beams added a comment - Hi Madis, This certainly makes sense and we'll look into it. Could you quickly verify the behavior against 3.1.0.RC1 or 3.1.0.BUILD-SNAPSHOT as well? It would also be useful if you could add a simple test case or reproduction project per https://github.com/SpringSource/spring-framework-issues#readme Thanks, Chris
        Hide
        Madis Pärn added a comment -

        verified in 3.1.0.BUILD-SNAPSHOT

        Show
        Madis Pärn added a comment - verified in 3.1.0.BUILD-SNAPSHOT
        Show
        Madis Pärn added a comment - added testcase https://github.com/SpringSource/spring-framework-issues/pull/9
        Hide
        Chris Beams added a comment -

        Madis,

        Please take a look at the commit history for spring-framework-issues under the SPR-8813 directory.

        In short, addressing this issue within the framework is not feasible because doing so consistently for JDK proxies as well as CGLIB proxies requires use of spring-aop's Advised interface. This creates a cycle between spring-beans and spring-aop. However, all the tests now pass by calling out to a simple utility method named unwrapAopProxyIfNecessary():

                private static Object unwrapAopProxyIfNecessary(Object bean) {
                        if (AopUtils.isAopProxy(bean)) {
                                try {
                                        return ((Advised)bean).getTargetSource().getTarget();
                                } catch (Exception ex) {
                                        throw new IllegalStateException("AOP proxy target cannot be resolved", ex);
                                }
                        }
                        return bean;
                }
        

        This utility method would be suitable for inclusion in your MyPropertyPlaceholderConfigurer, for example.

        Again, please take a look at the complete git log and commit comments for details.

        Show
        Chris Beams added a comment - Madis, Please take a look at the commit history for spring-framework-issues under the SPR-8813 directory. In short, addressing this issue within the framework is not feasible because doing so consistently for JDK proxies as well as CGLIB proxies requires use of spring-aop's Advised interface. This creates a cycle between spring-beans and spring-aop. However, all the tests now pass by calling out to a simple utility method named unwrapAopProxyIfNecessary() : private static Object unwrapAopProxyIfNecessary( Object bean) { if (AopUtils.isAopProxy(bean)) { try { return ((Advised)bean).getTargetSource().getTarget(); } catch (Exception ex) { throw new IllegalStateException( "AOP proxy target cannot be resolved" , ex); } } return bean; } This utility method would be suitable for inclusion in your MyPropertyPlaceholderConfigurer , for example. Again, please take a look at the complete git log and commit comments for details.

          People

          • Assignee:
            Chris Beams
            Reporter:
            Madis Pärn
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 25 weeks ago