I am new to Camel and am learning as I go. There seem to be lots of possible ways to exchange information between some framework (e.g. Spring Boot) and Camel. I'm having a hard time figuring out how (or even if) to do this from Spring Boot properties. By this I mean application.properties
or application.yml
.
The following SO item (Spring Boot properties usage in Apache Camel route) asks a very similar question, but the answers don't seem to work. I'll admit I don't really understand the last answer provided.
So what am I trying to do? Since I'm still very new at Camel, I'm doing something really basic and simple. I have a very small Spring Boot application that uses Camel to simply copy a file from one location to another.
Here's my route:
src/main/java/mypackage/CopyFileRoute.java:
@Component
public class CopyFileRoute extends RouteBuilder {
@Override
//@formatter:off
public void configure() throws Exception {
this
.from("file:{{properties.source-path}}/{{properties.file-name}}?noop=true")
.to("file:{{properties.dest-path}}/{{properties.file-name}}");
}
//@formatter:on
}
src/main/resources/application.yml:
properties:
source-path: demo/copyFrom
dest-path: demo/copyTo
file-name: test.txt
I've read about property substitution (or placeholders) in the Camel user guide (https://camel.apache.org/manual/latest/using-propertyplaceholder.html and https://camel.apache.org/components/latest/properties-component.html), but cannot get it to work. Granted, the examples in the user guide are in XML configuration, where I'm doing it in Java configuration. Does this not work in Java code?
BTW, I tried to incorporate the Camel property "bridge" (BridgePropertyPlaceholderConfigurer
), but that doesn't work either. I'm not sure how I'm supposed to utilize it.
UPDATE:
I tried the following with the "bridge", but alas, that also does not work:
@Configuration
@ComponentScan("mypackage")
public class Configurer {
@Bean
public CamelContext camelContext() {
return new DefaultCamelContext();
}
@Bean
public BridgePropertyPlaceholderConfigurer bridgePropertyPlaceholder() {
BridgePropertyPlaceholderConfigurer bridge = new BridgePropertyPlaceholderConfigurer();
bridge.setLocation(new ClassPathResource("application.properties"));
return bridge;
}
}