我使用的是弹簧靴2.2.4.RELEASE和骆驼版2.23.0
为了使骆驼可以访问属性并在uri路由中使用它们{{ }}
添加camel-spring-boot-starter依赖和定义PropertySourcesPlaceholderConfigurer,SpringCamelContextbean就足够了
@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遵循迁移指南并修复了组件的导入之后。在运行时,骆驼找不到属性,我得到了这个:
Property with key [xxx] not found in properties from text: activemq:queue:{{xxx}}
任何想法发生了什么变化,为什么{{ }}我的路线不再起作用?
更新 1
我更新了弹簧靴来回,我2.2.6.RELEASE仍然得到同样的东西camel-spring-boot-starter......3.2.0org.apache.camel.springboot
路线并不花哨。
我需要{{ }}从中读取xxx值myProperties.properties
使用@Value("${xxx}")works,spring可以访问它,我可以将它传递给路由URI字符串。
在骆驼 URI 中访问{{xxx}}是更新后停止工作的原因。
@Component
public class MyRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("activemq:queue:{{xxx}}")
.to("activemq:topic:targetTopic");
}
}
更新 2
我反映了接受答案所做的测试。去除SpringCamelContext和PropertySourcesPlaceholderConfigurer豆子就可以了。
我取出了豆子SpringCamelContext,它起作用了。显然,这个新的 spring camel starter 会SpringCamelContext自行处理,我的 bean 使用了与骆驼读取属性相关的自动配置{{ }}
我还删除了 bean PropertySourcesPlaceholderConfigurer,@Value 并没有停止工作。