easier framework support for the creation & injection of a bean by its class [SPR-4594] #9271
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
James Strachan opened SPR-4594 and commented
Now that a bean can be annotated with
@Service
/@Component
its no longer required to be inside an ApplicationContext for Spring to be able to instantiate and inject it. Yet from the public Spring context API the only choice you've got is to access beans by name. (Unless I've missed something :)There are numerous frameworks out there that want to create an instance of some type easily (without it necessarily being in the spring.xml). Off the top of my head here's a few I've seen some icky code to integrate spring injection but am sure there's loads more...
Now in Guice its super easy. You do things like
You're done; all the nice IoC is done by the injector which is a framework developers dream.
When using Spring now we've got 2.5.x its kinda hacky.
e.g. here's some code from trying to use Spring nicely inside JAX-RS (Jersey). Notice its trying to find bean names; then if not it tries to use the BeanFactory in the appContext. This doesn't deal with things like the
@Component
/@Service
use case though.Now maybe SpringSource are now thinking, to hell with frameworks just use the Spring porfolio for everything bwaahahhahaha.
However one of the big factors for Spring's success has always been that it works nicely with loads of different frameworks (struts v stripes v tapestry et al). So I'm wondering would you consider writing some kind of SpringInjector helper class?
So a framework could do something like...
This could then do things like; look for a single instance of MyStartClass in the bean names and use that if specified (fail if there's more than one); or if not treat it as a kinda
@Component
/@Service
type and call its constructors and any other@Autowired
/@Resource
injection points etc.i.e. now that there's the mixed model of stuff by name in the app context and stuff on the classpath which are types; could we have a simple unified injector API please for us poor hackers who sometimes dare to work with a framework which is not currently developed by SpringSource? :). Or - could Spring please catch up with Guice in the ease of use stakes as being an IoC framework? :)
Affects: 2.5.2
Issue Links:
4 votes, 3 watchers
The text was updated successfully, but these errors were encountered: