Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Sep 8, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. spring-projects-issues commented on Sep 8, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  3. spring-projects-issues commented on Sep 8, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  4. spring-projects-issues commented on Sep 8, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Mike Youngstrom commented

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

    Thanks,
    Mike

  5. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions