spring-bootapache-camelapache-camel-3

Camel cannot find {{xxx}} in properties from text after update to camel 3.0.0-RC3 using spring boot 2.2.4


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.


Solution

  • 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")