users@jersey.java.net

Re: [Jersey] Multiple dependent beans causing error

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Fri, 13 Aug 2010 14:21:15 +0200

Hi Mike,

I am not quite sure what is going on and why there is an ambiguity
when referring to the ServiceInterface for properties of that. The
error is referring to a different type,
com.liveensure.dao.admin.ConsumerDao. Are you using @Inject in other
areas as well?

If you can send a runnable test case (preferably a maven project) that
would help a lot.

Another solution in this case might be to utilize Spring's auto-wired
injection. Which you can use if you don't need to inject on a method
that Jersey is responsible for invoking e.g. a resource method
annotated with @GET.

Paul.


On Aug 13, 2010, at 12:24 AM, Mikey wrote:

> I have a Jersey project integrated with spring that uses multiple
> context files and merges them in web.xml like follows:
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>
> classpath*:/module1.xml
> classpath*:/module2.xml
> classpath*:/module3.xml
> classpath*:/module4.xml
> </param-value>
> </context-param>
>
> I have 2 beans with different names implementing the same interface
> in module3 and module4 spring config's. In module2 I have a class
> that uses one of those two beans.
>
> eg.
>
> In module3:
>
> <bean id="beanFoo" class="com.foo.FooInterface"/>
>
> In module4:
>
> <bean id="beanBar" class="com.foo.FooInterface"/>
>
> In module2:
>
> <bean id="moduleService" class="com.foo.ServiceInterface">
> <property name="fooDependency" ref="beanFoo"/>
> </bean>
>
> In my Jersey resource I inject the moduleService using @Inject:
>
> @Inject
> private ServiceInterface moduleService;
>
> However when I run this configuration I get the following runtime
> exception:
>
> SEVERE: Exception occurred when intialization
> java.lang.RuntimeException: There are multiple beans configured in
> spring for the type com.liveensure.dao.admin.ConsumerDao.
> Annotation information was not available, the reason might be
> because you're not using @Inject. You should use @Inject and
> specifiy the bean name via Inject("yourBean").
> Available bean names: beanFoo, beanBar
>
> I can't seem to figure out why Jersey is doing any sort of
> dependency checking and also unable to determine which bean is being
> used by the moduleService bean.
>
> I am not using component scan in the Jersey spring config. but
> rather explicitly defining the bean names. However I do let the
> @Inject introspect the moduleService so I'm guessing this is where
> my trouble lies, I just can't figure out if/why the explicit
> definition of moduleService isn't being used when looking to inject
> the bean. Any help/pointers/forehead smacks are greatly appreciated.
>
> Cheers.
>
> Mike
>
>
>
> --
> MiKey