Spring Boot auto-configuration not working for Apache Camel Bindy

294 Views Asked by At

As described here, and in the official documentation itself: the unwrapSingleInstance property allows us to establish "when unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List".

However, the camel.dataformat.bindy-csv.unwrap-single-instance auto-configuration property of Spring Boot has no effect on the documentation example:

BindyCsvDataFormat bindy = new BindyCsvDataFormat(com.acme.model.MyModel.class);

from("file://inbox")
  .unmarshal(bindy)
  .to("direct:handleOrders");

The above example only works by setting the property this way, directly in the code:

bindy.setUnwrapSingleInstance(false);

I guess this is because the new BindyCsvDataFormat object is not managed by Spring, so how can I get Spring to create and manage it for auto-configuration to take effect in Apache Camel?


I tried to create a regular bean in Spring and set the reference in unmarshal, and auto-configuration has no effect either:

@Bean
public DataFormat bindyCsvDataFormat() {
    return new BindyCsvDataFormat(com.acme.model.MyModel.class);
}

from("file://inbox")
  .unmarshal("bindyCsvDataFormat")
  .to("direct:handleOrders");

I have this dependency in pom.xml with Apache Camel version 3.20.5:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-bindy-starter</artifactId>
</dependency>
1

There are 1 best solutions below

4
TacheDeChoco On

Have a look at the two following classes:

https://github.com/apache/camel-spring-boot/tree/main/components-starter/camel-bindy-starter/src/main/java/org/apache/camel/dataformat/bindy/csv/springboot

As you will see, Camel will "auto-mount" several Bindy-oriented classes, so that they will be auto-wired when Spring(Boot) is going to instantiate the bindy component.

And that case, you should of course NOT create your beans using the vanilla constructor (eg new BindyCsvDataFormat)