You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide support for javax.inject.Provider<> style injection for @Value and @Autowired [SPR-6079] #10747
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.
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.
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.
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.
Activity
spring-projects-issues commentedon Sep 8, 2009
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 commentedon Sep 8, 2009
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 commentedon Sep 8, 2009
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
@Valueexpression.Juergen
spring-projects-issues commentedon Sep 8, 2009
Mike Youngstrom commented
You rock!!! Looking at the source changes it appears to be just what I was looking for.
Thanks,
Mike