0

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>
lcnicolau
  • 3,252
  • 4
  • 36
  • 53

1 Answers1

1

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)

TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17
  • Thanks, but how can I do it? I tried to create a regular bean in Spring and it has no effect (I updated the question with the details). – lcnicolau Jul 20 '23 at 16:57
  • Do you use the `camel-bindy-starter` dependency (and not the `camel-bindy`) ? – TacheDeChoco Jul 20 '23 at 18:41
  • By using it, Spring will auto load the beans specified in https://github.com/apache/camel-spring-boot/blob/main/components-starter/camel-bindy-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports – TacheDeChoco Jul 20 '23 at 18:43
  • I have the correct dependency in `pom.xml` with Apache Camel version `3.20.5` – lcnicolau Jul 21 '23 at 15:29