users@jersey.java.net

IoC: Inject instance of type that has two configured beans

From: Martin Grotzke <martin.grotzke_at_freiheit.com>
Date: Fri, 06 Jun 2008 09:08:19 +0200

Hi,

the @Inject has currently one limitation: it just can fetch a bean based
on the field's type. E.g. when we have this resource:

@Path("/foo")
class Resource {
    private @Inject Properties _props1;
    ....
}

the ComponentProvider will be asked for a bean of type Properties. If
there are two beans of type Properties configured in the spring
applicationContext (or the IoC-config), the ComponentProvder cannot
decide which bean to return and therefore will fail.

Regarding the spring-integration it would be good to get some
information about the @Inject annotation or even the field.

Then one could extend @Inject with some "value" or "hint" property that
can be evaluated by the ComponentProvider, of, if the field would be
handed to the CP, one could e.g. use the field.name as a hint regarding
the desired bean. I would prefer the first option, as it's more explicit
and more self-explaining.

I think we have two choices:
1) Extend the ComponentProvider
2) Create some @InjectBean annotation just for the spring-integration
   that will be handled by the SpringComponentProvider

What do you think?

Cheers,
Martin