2

I was using spring boot 2.2.4.RELEASE and camel version 2.23.0

In order to make camel have access to properties and use them in uri routes using {{ }}

adding camel-spring-boot-starter dependency and defining PropertySourcesPlaceholderConfigurer, SpringCamelContext bean was enough to make it work

@SpringBootApplication
@PropertySource(ignoreResourceNotFound = false, value= {"classpath:myProperties.properties"})
public class MyApp {

    ...
    @Bean
    public SpringCamelContext camelContext(ApplicationContext applicationContext) {
        return new SpringCamelContext(applicationContext);
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}

--

Now, after I updated camel-spring-boot-starter to 3.0.0-RC3 following the migration guide and after fixing the imports for the components. On runtime, camel cannot find properties and I get this:

Property with key [xxx] not found in properties from text: activemq:queue:{{xxx}}

Any Ideas what changed and why {{ }} is not working anymore in my routes?


UPDATE 1

I updated spring boot to 2.2.6.RELEASE and camel-spring-boot-starter to 3.2.0 from org.apache.camel.springboot I am still getting the same thing...

Routes are not fancy.

I need for {{ }} to read xxx value from myProperties.properties

Using @Value("${xxx}") works, spring can access it, and I could pass it to the route URI String.

Accessing {{xxx}} in camel URIs is what stopped working after the update.

@Component
public class MyRoutes extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("activemq:queue:{{xxx}}")
            .to("activemq:topic:targetTopic");
    }
}

UPDATE 2

I mirrored the test made by accepted answer. Removing SpringCamelContext and PropertySourcesPlaceholderConfigurer beans did the trick.

I removed the bean SpringCamelContext and it worked. Apparently this new spring camel starter takes care of SpringCamelContext by itself and my bean overrode the auto configuration related to camel reading properties using {{ }}

I also removed the bean PropertySourcesPlaceholderConfigurer and @Value did not stop working.

aboudirawas
  • 192
  • 3
  • 21

1 Answers1

2

Are you using the application.properties file in your spring boot application? If so {{}} should work. It would help to see your camel code though.

Edit 1:

This works for me. I am running Camel 3.2.0 with Spring Boot 2.2.6. I have a single property prop=Hello World in a file myProperties.properties in my classpath. I did not have to define the PropertySourcesPlaceholderConfigurer and SpringCamelContext beans

@SpringBootApplication
@PropertySource(ignoreResourceNotFound = false, value = {"classpath:myProperties.properties"})
public class DemoApplication extends RouteBuilder{

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void configure() throws Exception {
        from("timer:foo?repeatCount=1")
        .log("{{prop}}");
    }
}

Log

2020-04-28 21:26:57.904  INFO 10392 --- [  restartedMain] o.a.c.impl.engine.AbstractCamelContext   : Route: route6 started and consuming from: timer://foo
2020-04-28 21:26:57.921  INFO 10392 --- [  restartedMain] o.a.c.impl.engine.AbstractCamelContext   : Total 1 routes, of which 1 are started
2020-04-28 21:26:57.937  INFO 10392 --- [  restartedMain] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.2.0 (CamelContext: camel-6) started in 0.067 seconds
2020-04-28 21:26:57.938  INFO 10392 --- [  restartedMain] c.p.testproperties.DemoApplication       : Started DemoApplication in 0.406 seconds (JVM running for 82.808)
2020-04-28 21:26:57.955  INFO 10392 --- [  restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
2020-04-28 21:26:58.920  INFO 10392 --- [4 - timer://foo] route6                                   : Hello World

Edit 2:

You may be fetching your property from the Exchange, which may cause this issue. Fetching properties from the exchange has been changed since Camel version 3.0.0. Can you try exchangeProperty("xxx")

Sneharghya Pathak
  • 990
  • 1
  • 9
  • 19
  • I updated my question. There is nothing special or relevant in application.properties. there is nothing special about the routes as well. routes having `{{xxx}}` used to work before the update. – aboudirawas Apr 28 '20 at 13:50
  • Added a test in the edits. It is working fine for me! – Sneharghya Pathak Apr 28 '20 at 16:01
  • 2
    I removed the two beans `PropertySourcesPlaceholderConfigurer` and `SpringCamelContext` and it worked. I think it has something to do with camel 3 allowing one only camel context to run so the starter package did the job and my `SpringCamelContext` overrode it along with the auto config related to properties. Marking as accepted answer. Thanks. – aboudirawas Apr 29 '20 at 06:51