使用spring boot 2.2.4更新到camel 3.0.0-RC3后,Camel在文本属性中找不到{{xxx}} [英] Camel cannot find {{xxx}} in properties from text after update to camel 3.0.0-RC3 using spring boot 2.2.4
问题描述
我用的是spring boot 2.2.4.RELEASE
和camel版本2.23.0
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 {{ }}
添加 camel-spring-boot-starter
依赖并定义 PropertySourcesPlaceholderConfigurer
, SpringCamelContext
bean 足以让它工作
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();
}
}
--
现在,在我按照迁移指南将 camel-spring-boot-starter
更新为 3.0.0-RC3
并修复了组件的导入之后.在运行时,骆驼找不到属性,我得到了这个:
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:
在文本属性中找不到键 [xxx] 的属性:activemq:queue:{{xxx}}
任何想法发生了什么变化以及为什么 {{ }}
在我的路线中不再起作用?
Any Ideas what changed and why {{ }}
is not working anymore in my routes?
更新 1
我将 spring boot 更新为 2.2.6.RELEASE
和 camel-spring-boot-starter
从 更新为
我仍然得到同样的东西......3.2.0
org.apache.camel.springboot
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...
路线并不花哨.
我需要 {{ }}
从 myProperties.properties
使用 @Value("${xxx}")
有效,spring可以访问它,我可以将它传递给路由URI字符串.
Using @Value("${xxx}")
works, spring can access it, and I could pass it to the route URI String.
在骆驼 URI 中访问 {{xxx}}
是更新后停止工作的原因.
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");
}
}
<小时>
更新 2
我反映了接受答案所做的测试.删除 SpringCamelContext
和 PropertySourcesPlaceholderConfigurer
bean 就可以了.
I mirrored the test made by accepted answer. Removing SpringCamelContext
and PropertySourcesPlaceholderConfigurer
beans did the trick.
我删除了 bean SpringCamelContext
并且它起作用了.显然,这个新的 spring camel starter 自己处理了 SpringCamelContext
并且我的 bean 使用 {{ }}
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 {{ }}
我还删除了 bean PropertySourcesPlaceholderConfigurer
并且 @Value 没有停止工作.
I also removed the bean PropertySourcesPlaceholderConfigurer
and @Value did not stop working.
推荐答案
你在你的spring boot应用中使用了application.properties文件吗?如果是这样 {{}} 应该可以工作.不过,查看您的骆驼代码会有所帮助.
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.
编辑 1:
这对我有用.我正在使用 Spring Boot 2.2.6 运行 Camel 3.2.0.我的类路径中的文件 myProperties.properties
中有一个属性 prop=Hello World
.我不必定义 PropertySourcesPlaceholderConfigurer
和 SpringCamelContext
beans
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}}");
}
}
日志
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
编辑 2:
您可能正在从交易所取回您的财产,这可能会导致此问题.自 Camel 版本 3.0.0 以来,从交换中获取属性已更改.你可以试试exchangeProperty("xxx")
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")
这篇关于使用spring boot 2.2.4更新到camel 3.0.0-RC3后,Camel在文本属性中找不到{{xxx}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!