Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15042

Regression with poolTargetSource and scoped proxy

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.4
    • Fix Version/s: 4.3.6, 5.0 M4
    • Component/s: Core:DI
    • Labels:

      Description

      It seems that this which is pretty much straight from docs works with 4.3.3 but not with 4.3.4, 4.3.5 or 5.0.0.BUILD-SNAPSHOT.

      @Bean
      @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
      public ProxyFactoryBean myObject() {
      	ProxyFactoryBean pfb = new ProxyFactoryBean();
      	pfb.setTargetSource(poolTargetSource());
      	return pfb;
      }
      
      @Bean
      public CommonsPool2TargetSource poolTargetSource() {
      	CommonsPool2TargetSource pool = new CommonsPool2TargetSource();
      	pool.setMaxSize(3);
      	pool.setTargetBeanName("myObjectTarget");
      	return pool;
      }
      
      @Bean(name = "myObjectTarget")
      @Scope(scopeName="prototype")
      public Object myObjectTarget() {
      	return new Object();
      }
      
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myObject' defined in BeanDefinition defined in com.example.ScopeConfiguration: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.myObject': Target type could not be determined at the time of proxy creation.
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:577)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:484)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:424)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:419)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:385)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:503)
      	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getSinglePropertySourcesPlaceholderConfigurer(ConfigurationPropertiesBindingPostProcessor.java:259)
      	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.deducePropertySources(ConfigurationPropertiesBindingPostProcessor.java:238)
      	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.afterPropertiesSet(ConfigurationPropertiesBindingPostProcessor.java:202)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1668)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1605)
      	... 59 more
      Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.myObject': Target type could not be determined at the time of proxy creation.
      	at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:96)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1628)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1596)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:568)
      	... 73 more
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              jvalkeal Janne Valkealahti
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 36 weeks, 4 days ago