camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Type converters with Spring
Date Tue, 31 Mar 2009 10:04:27 GMT
Hi

Or pass in Exchange as the 2nd parameter.
Using Exchange you can get hold on the CamelContext and thus the
registry as well, and do lookup for Spring beans.



On Tue, Mar 31, 2009 at 12:01 PM, James Strachan
<james.strachan@gmail.com> wrote:
> 2009/3/31 Martin Gilday <martin.lists@imap.cc>:
>> I'd like to have a converter which uses a Spring @service to do lookups.
>>  According to the docs "If a converter requires configuration you can
>> plug in an Injector interface to the DefaultTypeConverter which can
>> construct and inject converter objects via Spring or Guice."
>>
>> I'm unsure what it means by working with the DefaultTypeConverter. Are
>> there any examples which show how to do this?
>
> You could try something like this
>
> public class MyServiceConverter implements ApplicationContextAware {
>  ApplicationContext context;
>
>  @Converter
>  public MyType convert(String name) {
>   return context.getbean(name, MyType.class);
>  }
> }
>
> letting spring do whatever dependency injection you require on the
> converter object
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://fusesource.com/
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration

Mime
View raw message