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

Provide support for javax.inject.Provider<> style injection for @Value and @Autowired [SPR-6079] #10747

Closed
spring-projects-issues opened this issue Sep 4, 2009 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 4, 2009

Mike Youngstrom opened SPR-6079 and commented

Sometimes for @EL and @Autowired injection points the developer may not want the expression or the dependency evaluated at the time of injection but instead at a later point when the developer chooses to evaluate the injection. This is extremely useful for a number of reasons. Some of which are detailed in the javax.inject.Provider javadocs here.

http://atinject.googlecode.com/svn/trunk/javadoc/javax/inject/Provider.html

With the added desire that the injected Provider be Serializable.

It would be nice if specifically this portion of the javax.inject functionality could be included in Spring 3.0 since it is so valuable especially when coupled with @Value. I would be happy to provide an initial patch if there were a chance for this to make it into Spring 3.0.


Affects: 3.0 M4

Issue Links:

Referenced from: commits 209f43b

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We actually have such an interface already: org.springframework.beans.factory.ObjectFactory. It's not promoted much but has been around for a while, usually to be set up via an ObjectFactoryCreatingFactoryBean (pretty old school, I know). We are also using the ObjectFactory interface in other scenarios, e.g. in the Scope SPI.

So I guess there is an obvious solution: Supporting injection of a generically typed ObjectFactory<T> using @Autowired / @Value. I'll prototype this for the Spring 3.0 timeframe still; if it's easy enough to do, it still has a chance to make it into 3.0. We'll fully support the actual JSR-330 Provider facility in Spring 3.1 then.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Mike Youngstrom commented

Ah, forgot about ObjectFactory. That would be perfect. If it would help getting it into 3.0 I could provide am initial PoC patch. Let me know.

Mike

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Should work fine in SVN trunk already :-)

We respect the generically declared ObjectFactory type <T>, if available. Otherwise we'll simply create a standard ObjectFactory<Object>, with the matching done against qualifiers or based on the @Value expression.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Mike Youngstrom commented

You rock!!! Looking at the source changes it appears to be just what I was looking for.

Thanks,
Mike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants