Search code examples
javaspringapache-camelbindy

Camel Bindy: providing the class to use in spring.xml


I am sure I have missed something really obvious but just haven’t worked it out.

We use bindy to extract a CSV file into a POJO . This has been working nice and well. We have been given some more CSV files to load. This is where I discovered the issue. Bindy doesn’t allow multiple classes to have the @CsvRecord annotation to live in the same package if you do a package scan. But that is ok since we use camel 2.13.3 and I can see that the constructor for BindyCsvDataFormat allows us to pass in a class.

The trouble I am having is, we use spring.xml to setup camel. I can’t seem to get the BindyCsvDataFormat to use the class constructor. It will only use the one that does a package scan.

<bean id="bindyDataformat" class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
    <constructor-arg value="com.something.package.Model.class" />
</bean>

The above didn’t work. I suspect it is with me passing a string as the constructor-arg so the string constructor is always called. Is there a way to get BindyCsvDataFormat to not do the package scan and to allow me to provide the class I want the csv data unmarshalled to in the spring.xml?


Solution

  • What you are trying to do is not specific to bindy. It's a common problem where you need to inject the "value" of a Class via Spring DI.

    Here's a link that describes how to do pass a class argument properly:

    pass "HardCoded" Constructor Arg Class<T> to bean via Spring Config