You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Christian Koller <ko...@swissonline.ch> on 2010/07/26 16:54:58 UTC
Tapestry 5 and Spring beans with same interface
Hi all
I want to use two different spring beans with same interface in my module class, like the example shows:
public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
@Inject RequestFilter handsetGroupRequestFilter,
@Inject RequestFilter deviceRecognitionRequestFilter) {
configuration.add("HandsetGroupRequestFilter", handsetGroupRequestFilter);
configuration.add("DeviceRecognitionRequestFilter", deviceRecognitionRequestFilter);
}
Of course i get an exception like:
Spring context contains 2 beans assignable to type org.apache.tapestry5.services.RequestFilter: deviceRecognitionRequestFilter, handsetGroupRequestFilter.
How can I solve this problem? Somehow I have to provide the spring bean id.
thx
chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry 5 and Spring beans with same interface
Posted by Jonathan Barker <jo...@gmail.com>.
You could create two new interfaces that extend RequestFilter (say
HandsetGroupRequestFilter and DeviceRecognitionRequestFilter) whose sole
purpose is to allow you to distinguish between the beans. Then inject the
two different interfaces.
On Mon, Jul 26, 2010 at 11:00 AM, Christian Koller <
christian.koller@net-m.ch> wrote:
> Is there a better solution than this here:
>
> http://stackoverflow.com/questions/2684171/tapestry-5-and-spring-beans-with-same-interface
>
> Begin forwarded message:
>
> > From: Christian Koller <ko...@swissonline.ch>
> > Date: 26. Juli 2010 16:54:58 MESZ
> > To: Tapestry users <us...@tapestry.apache.org>
> > Subject: Tapestry 5 and Spring beans with same interface
> >
> > Hi all
> >
> > I want to use two different spring beans with same interface in my module
> class, like the example shows:
> >
> > public void contributeRequestHandler(OrderedConfiguration<RequestFilter>
> configuration,
> > @Inject RequestFilter handsetGroupRequestFilter,
> > @Inject RequestFilter deviceRecognitionRequestFilter) {
> >
> > configuration.add("HandsetGroupRequestFilter",
> handsetGroupRequestFilter);
> > configuration.add("DeviceRecognitionRequestFilter",
> deviceRecognitionRequestFilter);
> > }
> >
> > Of course i get an exception like:
> > Spring context contains 2 beans assignable to type
> org.apache.tapestry5.services.RequestFilter: deviceRecognitionRequestFilter,
> handsetGroupRequestFilter.
> >
> >
> > How can I solve this problem? Somehow I have to provide the spring bean
> id.
> > thx
> > chris
>
> Christian Koller
> Sofwareentwickler
>
> net mobile Schweiz AG
> Seestrasse 45
> CH ñ 8702 Zollikon
>
> Tel: + 41 (0) 44 918 99 99
> Fax: + 41 (0) 44 918 99 98
> Direkt: + 41 (0) 44 918 99 72
>
> Mail: christian.koller@net-m.ch
> Web: www.net-m.ch
>
>
--
Jonathan Barker
ITStrategic
Re: Tapestry 5 and Spring beans with same interface
Posted by Jonathan Barker <jo...@gmail.com>.
I had tried this. It doesn't seem to be supported. From the docs for
tapestry-ioc:
SpringBean ObjectProvider (tapestry-spring)
Attempts to resolve a Spring bean purely by object type (Spring qualifiers
are not supported). If no beans are assignable to the type, then processing
continues. If exactly one is assignable, it is used as the injection value.
If more than one bean is assignable, it is an error (and a list of matching
beans names will be part of the thrown exception).
I came across a description of how to do it in a less ugly fashion (sorry, I
can't find a reference to it, but it might very well be the same solution
originally given). I had problems getting it to work, whatever it was, and
I needed to move forward. Hence my workaround. I do miss the ability to
inject by id.
JB
On Mon, Jul 26, 2010 at 12:14 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> On Mon, 26 Jul 2010 12:00:50 -0300, Christian Koller <
> christian.koller@net-m.ch> wrote:
>
> Is there a better solution than this here:
>>
>> http://stackoverflow.com/questions/2684171/tapestry-5-and-spring-beans-with-same-interface
>>
>
> What about using @InjectService("serviceId")?
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Jonathan Barker
ITStrategic
Re: Tapestry 5 and Spring beans with same interface
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 26 Jul 2010 12:00:50 -0300, Christian Koller
<ch...@net-m.ch> wrote:
> Is there a better solution than this here:
> http://stackoverflow.com/questions/2684171/tapestry-5-and-spring-beans-with-same-interface
What about using @InjectService("serviceId")?
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Tapestry 5 and Spring beans with same interface
Posted by Christian Koller <ch...@net-m.ch>.
Is there a better solution than this here:
http://stackoverflow.com/questions/2684171/tapestry-5-and-spring-beans-with-same-interface
Begin forwarded message:
> From: Christian Koller <ko...@swissonline.ch>
> Date: 26. Juli 2010 16:54:58 MESZ
> To: Tapestry users <us...@tapestry.apache.org>
> Subject: Tapestry 5 and Spring beans with same interface
>
> Hi all
>
> I want to use two different spring beans with same interface in my module class, like the example shows:
>
> public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
> @Inject RequestFilter handsetGroupRequestFilter,
> @Inject RequestFilter deviceRecognitionRequestFilter) {
>
> configuration.add("HandsetGroupRequestFilter", handsetGroupRequestFilter);
> configuration.add("DeviceRecognitionRequestFilter", deviceRecognitionRequestFilter);
> }
>
> Of course i get an exception like:
> Spring context contains 2 beans assignable to type org.apache.tapestry5.services.RequestFilter: deviceRecognitionRequestFilter, handsetGroupRequestFilter.
>
>
> How can I solve this problem? Somehow I have to provide the spring bean id.
> thx
> chris
Christian Koller
Sofwareentwickler
net mobile Schweiz AG
Seestrasse 45
CH ñ 8702 Zollikon
Tel: + 41 (0) 44 918 99 99
Fax: + 41 (0) 44 918 99 98
Direkt: + 41 (0) 44 918 99 72
Mail: christian.koller@net-m.ch
Web: www.net-m.ch
Tapestry 5 and Spring beans with same interface
Posted by Christian Koller <ch...@net-m.ch>.
Hi all
Thank you for your great support.
@Igor
Yes I'm talking about spring beans and yes RequestFilter is a tapestry interface.
I wanted to use it like this in the spring context:
<bean id="handsetGroupRequestFilter" class="xxx.yyy.HandsetGroupRequestFilter">
</bean>
<bean id="deviceRecognitionRequestFilter" class="xxx.yyy.DeviceRecognitionRequestFilter">
<property name="deviceService" ref="deviceService" />
</bean>
Consider the deviceRecognitionRequestFilter is using the spring bean deviceService.
On 26.07.2010, at 19:09, Igor Drobiazko wrote:
> Hi Christian,
>
> are you sure you are talking about Spring beans? RequestFilter is a Tapestry
> interface. You should provide implementations for this interface inside a
> Tapestry module. As Thiago suggested you should use @InjectService to
> disambiguate both implementations.
>
> On Mon, Jul 26, 2010 at 4:54 PM, Christian Koller <ko...@swissonline.ch>wrote:
>
>> Hi all
>>
>> I want to use two different spring beans with same interface in my module
>> class, like the example shows:
>>
>> public void contributeRequestHandler(OrderedConfiguration<RequestFilter>
>> configuration,
>> @Inject RequestFilter handsetGroupRequestFilter,
>> @Inject RequestFilter deviceRecognitionRequestFilter) {
>>
>> configuration.add("HandsetGroupRequestFilter", handsetGroupRequestFilter);
>> configuration.add("DeviceRecognitionRequestFilter",
>> deviceRecognitionRequestFilter);
>> }
>>
>> Of course i get an exception like:
>> Spring context contains 2 beans assignable to type
>> org.apache.tapestry5.services.RequestFilter: deviceRecognitionRequestFilter,
>> handsetGroupRequestFilter.
>>
>>
>> How can I solve this problem? Somehow I have to provide the spring bean id.
>> thx
>> chris
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
Christian Koller
Sofwareentwickler
net mobile Schweiz AG
Seestrasse 45
CH ñ 8702 Zollikon
Tel: + 41 (0) 44 918 99 99
Fax: + 41 (0) 44 918 99 98
Direkt: + 41 (0) 44 918 99 72
Mail: christian.koller@net-m.ch
Web: www.net-m.ch
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry 5 and Spring beans with same interface
Posted by Igor Drobiazko <ig...@gmail.com>.
Hi Christian,
are you sure you are talking about Spring beans? RequestFilter is a Tapestry
interface. You should provide implementations for this interface inside a
Tapestry module. As Thiago suggested you should use @InjectService to
disambiguate both implementations.
On Mon, Jul 26, 2010 at 4:54 PM, Christian Koller <ko...@swissonline.ch>wrote:
> Hi all
>
> I want to use two different spring beans with same interface in my module
> class, like the example shows:
>
> public void contributeRequestHandler(OrderedConfiguration<RequestFilter>
> configuration,
> @Inject RequestFilter handsetGroupRequestFilter,
> @Inject RequestFilter deviceRecognitionRequestFilter) {
>
> configuration.add("HandsetGroupRequestFilter", handsetGroupRequestFilter);
> configuration.add("DeviceRecognitionRequestFilter",
> deviceRecognitionRequestFilter);
> }
>
> Of course i get an exception like:
> Spring context contains 2 beans assignable to type
> org.apache.tapestry5.services.RequestFilter: deviceRecognitionRequestFilter,
> handsetGroupRequestFilter.
>
>
> How can I solve this problem? Somehow I have to provide the spring bean id.
> thx
> chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Best regards,
Igor Drobiazko
http://tapestry5.de