0

I'm trying to pass a comma delimited list of values to my camel-context and have it split into a list of Strings. This is what I have so far, but how do I pass my comma delimited list to it. So that this bean will return a list of Strings. I know I can write code for this and be done with it, but want to see if its doable without writing any code for it.

<bean id="nodesList" class="java.lang.String" factory-method="split" >
       <constructor-arg name="regex" value=","/>
</bean>
  • Camel is backed by Spring, which supports comma-delimited parameters out of the box. If you assign a String property to a collection-typed bean field, Spring should automatically attempt to split your property by commas – Alex Savitsky Apr 19 '18 at 15:01
  • Would you be able to provide an example? @AlexSavitsky – Dhaval Desai Apr 19 '18 at 18:36
  • 1
    See https://stackoverflow.com/questions/11577547/what-is-the-easiest-way-to-specify-a-list-with-values-in-spring or https://stackoverflow.com/questions/12576156/reading-a-list-from-properties-file-and-load-with-spring-annotation-value - I believe this feature is available since Spring 3.0 – Alex Savitsky Apr 19 '18 at 18:41

2 Answers2

1

As Alex Savitsky pointed out, his hyperlinks worked like a charm. Posting it here as the answer so others can see it.

"See What is the easiest way to specify a list with values in Spring? or Reading a List from properties file and load with spring annotation @Value - I believe this feature is available since Spring 3.0"

0

You can easily do that by leveraging the Tokenizer that built into camel core. Your code would look something like this

from(START)
  .split(body().tokenize(","))
  .to(DEST)

Check the Splitter documentation for more detailed examples.

David
  • 579
  • 1
  • 5
  • 20