org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mock' defined in class path resource [com/foo/bar/services/functional/impl/remote-ejb-context.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation.

Spring JIRA | Cédric Vidal | 9 years ago
  1. 0

    Hi guys, I want to inject remote EJB3 Session Beans into some web components. It works fine with remote SLSB but I can't figure out how to inject a remote SFSB. For the SLSB, I use the following configuration which works fine: <jee:jndi-lookup id="registrationService" jndi-name="registrationService/local" cache="true" lookup-on-startup="true" proxy-interface="com.foo.bar.RegistrationService" /> I naturally need my remote SFSB session to last as long as my HTTP session lasts, and the session of the remote SFSB lasts as long as I hold a reference to the EJB proxy obtained from JNDI, so I guess I need to scope my JndiObjectFactoryBean to the web session. Since, the <jee:jndi-lookup/> element doesn't allow to configure the scope, I use the old fashioned JndiObjectFactoryBean configuration style. <bean id="userService" class="org.springframework.jndi.JndiObjectFactoryBean" scope="session"> <property name="jndiName" value="userService/remote"/> <property name="cache" value="true"/> <property name="lookupOnStartup" value="false"/> <property name="proxyInterface" value="com.foo.bar.UserService"/> <aop:scoped-proxy/> </bean> It fails with the following exception: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mock' defined in class path resource [com/foo/bar/services/functional/impl/remote-ejb-context.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation. at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:274) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at com.foo.bar.services.functional.impl.SpringTestFunctionalServiceClient.test(SpringTestFunctionalServiceClient.java:19) at com.foo.bar.services.functional.impl.SpringTestFunctionalServiceClient.main(SpringTestFunctionalServiceClient.java:15) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:268) ... 18 more Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation. at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:94) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1350) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540) ... 26 more As far as I understand, this is because, when the ScopedProxyFactoryBean.setBeanFactory is called, JndiObjectFactoryBean's underlying proxy has not been instanciated yet and ScopedProxyFactoryBean's beanFactory cannot figure out what the type of the target bean is. This is normal since we actually don't want the JNDI Proxy to be instanciated at this point. But JndiObjectFactoryBean actually knows what the type of the target bean is, through its proxyInterfaces property, and the AbstractBeanFactory.getType(String name) actually falls back to the JndiObjectFactoryBean.getObjectType method which eventually checks the proxyInterfaces so it should work ! The problem is that when the JndiObjectFactoryBean.getObjectType is called, the proxyInterfaces is null even if it has been properly configured on the BeanDefinition. I don't know Spring AOP and Spring's lifecycle well enough to figure out what a possible solution might be. I tried moving the setBeanFactory body to the afterPropertiesSet method but it didn't change anything. This problem might be related to a double proxy issue, which is mentionned here: http://forum.springframework.org/showthread.php?t=32645&highlight=ScopedProxyFactoryBean Jörg Heinicke mentions that a possible solution might be to move the scoping behavior to an interceptor (or an Advice i guess) so as to avoid the double proxy problem. Any help would be appreciated, Kind regards, Cédric

    Spring JIRA | 9 years ago | Cédric Vidal
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mock' defined in class path resource [com/foo/bar/services/functional/impl/remote-ejb-context.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation.
  2. 0

    Hi guys, I want to inject remote EJB3 Session Beans into some web components. It works fine with remote SLSB but I can't figure out how to inject a remote SFSB. For the SLSB, I use the following configuration which works fine: <jee:jndi-lookup id="registrationService" jndi-name="registrationService/local" cache="true" lookup-on-startup="true" proxy-interface="com.foo.bar.RegistrationService" /> I naturally need my remote SFSB session to last as long as my HTTP session lasts, and the session of the remote SFSB lasts as long as I hold a reference to the EJB proxy obtained from JNDI, so I guess I need to scope my JndiObjectFactoryBean to the web session. Since, the <jee:jndi-lookup/> element doesn't allow to configure the scope, I use the old fashioned JndiObjectFactoryBean configuration style. <bean id="userService" class="org.springframework.jndi.JndiObjectFactoryBean" scope="session"> <property name="jndiName" value="userService/remote"/> <property name="cache" value="true"/> <property name="lookupOnStartup" value="false"/> <property name="proxyInterface" value="com.foo.bar.UserService"/> <aop:scoped-proxy/> </bean> It fails with the following exception: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mock' defined in class path resource [com/foo/bar/services/functional/impl/remote-ejb-context.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation. at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:274) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at com.foo.bar.services.functional.impl.SpringTestFunctionalServiceClient.test(SpringTestFunctionalServiceClient.java:19) at com.foo.bar.services.functional.impl.SpringTestFunctionalServiceClient.main(SpringTestFunctionalServiceClient.java:15) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:268) ... 18 more Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation. at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:94) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1350) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540) ... 26 more As far as I understand, this is because, when the ScopedProxyFactoryBean.setBeanFactory is called, JndiObjectFactoryBean's underlying proxy has not been instanciated yet and ScopedProxyFactoryBean's beanFactory cannot figure out what the type of the target bean is. This is normal since we actually don't want the JNDI Proxy to be instanciated at this point. But JndiObjectFactoryBean actually knows what the type of the target bean is, through its proxyInterfaces property, and the AbstractBeanFactory.getType(String name) actually falls back to the JndiObjectFactoryBean.getObjectType method which eventually checks the proxyInterfaces so it should work ! The problem is that when the JndiObjectFactoryBean.getObjectType is called, the proxyInterfaces is null even if it has been properly configured on the BeanDefinition. I don't know Spring AOP and Spring's lifecycle well enough to figure out what a possible solution might be. I tried moving the setBeanFactory body to the afterPropertiesSet method but it didn't change anything. This problem might be related to a double proxy issue, which is mentionned here: http://forum.springframework.org/showthread.php?t=32645&highlight=ScopedProxyFactoryBean Jörg Heinicke mentions that a possible solution might be to move the scoping behavior to an interceptor (or an Advice i guess) so as to avoid the double proxy problem. Any help would be appreciated, Kind regards, Cédric

    Spring JIRA | 9 years ago | Cédric Vidal
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mock' defined in class path resource [com/foo/bar/services/functional/impl/remote-ejb-context.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation.
  3. 0

    problem in Spring session scope bean with AOP

    Stack Overflow | 7 years ago | Nachiket
    java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.currentUser': Target type could not be determined at the time of proxy creation.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring Bean initialization - Date passed as String via xml not working for step scope

    Stack Overflow | 2 weeks ago | Aayush Singhal
    java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.currentDate': Target type could not be determined at the time of proxy creation.
  6. 0

    Using Spring's Cachable annotation on methods that returns Hibernate objects

    Stack Overflow | 1 year ago | Jan Vladimir Mostert
    java.lang.IllegalStateException: Post-processor tried to replace bean instance of type [com.ahp.core.model.Session] with (proxy) object of type [com.sun.proxy.$Proxy66] - not supported for aspect-configured classes!

    2 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Cannot create scoped proxy for bean 'scopedTarget.userService': Target type could not be determined at the time of proxy creation.

      at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory()
    2. Spring AOP
      ScopedProxyFactoryBean.setBeanFactory
      1. org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:94)
      1 frame
    3. Spring Beans
      AbstractAutowireCapableBeanFactory$1.run
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1350)
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
      3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
      3 frames
    4. Java RT
      AccessController.doPrivileged
      1. java.security.AccessController.doPrivileged(Native Method)
      1 frame
    5. Spring Beans
      AbstractAutowireCapableBeanFactory$1.run
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
      2. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
      3. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
      4. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
      5. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
      6. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:268)
      7. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
      8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1274)
      9. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)
      10. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      11. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
      11 frames
    6. Java RT
      AccessController.doPrivileged
      1. java.security.AccessController.doPrivileged(Native Method)
      1 frame
    7. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
      2. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
      3. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
      4. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
      5. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
      6. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413)
      6 frames
    8. Spring Context
      ClassPathXmlApplicationContext.<init>
      1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)
      2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
      3. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
      4. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
      4 frames
    9. com.foo.bar
      SpringTestFunctionalServiceClient.main
      1. com.foo.bar.services.functional.impl.SpringTestFunctionalServiceClient.test(SpringTestFunctionalServiceClient.java:19)
      2. com.foo.bar.services.functional.impl.SpringTestFunctionalServiceClient.main(SpringTestFunctionalServiceClient.java:15)
      2 frames