Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically created java.inject.Provider cannot be injected into session scoped beans [SPR-9845] #14478

Closed
spring-projects-issues opened this issue Oct 1, 2012 · 1 comment
Assignees
Labels
in: core type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 1, 2012

Ivan Sopov opened SPR-9845 and commented

If I inject javax.inject.Provider for creating prototype scoped beans into session scoped beans it fails when creating second session:

2012-10-01 18:45:50.113:WARN::/pins/default
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionBeanWithDefaultProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.inject.Provider com.sopovs.moradanen.SessionBeanWithDefaultProvider.prototypePojoProvider; nested exception is java.lang.IllegalArgumentException: Can not set javax.inject.Provider field com.sopovs.moradanen.SessionBeanWithDefaultProvider.prototypePojoProvider to com.sopovs.moradanen.PrototypeBean
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)
at org.springframework.web.context.request.SessionScope.get(SessionScope.java:92)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectFactory.getObject(DefaultListableBeanFactory.java:1040)
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyProvider.get(DefaultListableBeanFactory.java:1056)
at com.sopovs.moradanen.DefaultProviderController.sayHello(DefaultProviderController.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...

I have created sample project reproducing the issue and published it on github: https://github.com/isopov/provider-in-session-with-spring


Affects: 3.1.2

Reference URL: https://github.com/isopov/provider-in-session-with-spring

Issue Links:

  • #13819 @Inject Provider or @Autowired ObjectFactory issue with session scoped bean ("duplicates")
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 1, 2012

Ivan Sopov commented

As a workaround it is possible to define custom singleton that contains injected Provider and inject this singleton into session scoped beans. This workaround is illustrated on github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants