当前位置: 首页 > 知识库问答 >
问题:

使用Spring引导2.2.4更新到骆驼3.0.0-RC3后,骆驼在文本中找不到{{xxx}}

柯波娃
2023-03-14

我使用的是Spring启动2.2.4。RELEASE和骆驼版2.23.0

为了使骆驼能够访问属性并使用它们在uri路线中使用{{ }}

添加camel-spring-boot-starter依赖项并定义propertysourcesplaceplaceconfigurerSpringCamelContextbean足以让它工作

@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并修复了组件的导入之后。在运行时,camel找不到属性,我得到以下信息:

在text:activemq:queue:{{xxx}的属性中找不到键为[xxx]的属性

你知道是什么改变了,为什么我的路线不再有效了吗?

更新1

我将spring boot更新为2.2.6。从org将驼峰Spring启动机释放到3.2.0。阿帕奇。骆驼springboot我还是得到了同样的东西。。。

路线并不花哨。

我需要{{}myProperties中读取xxx值。属性

使用@Value("${xxx}")工作,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

我镜像了接受答案所做的测试。删除SpringCamelContextProperty tySourcesPlaceholderConfigrerbean完成了任务。

我删除了beanSpringCamelContext,它成功了。显然,这个新的spring camel启动器本身负责SpringCamelContext,my bean使用{}

我还删除了beanpropertySourcesplaceConfigurer,@Value没有停止工作。


共有1个答案

姜晨
2023-03-14

你正在使用这个应用程序吗。spring boot应用程序中的属性文件?如果是这样的话,{}}应该有效。不过,查看您的驼峰代码会有所帮助。

编辑1:

这对我有用。我正在运行带有Spring Boot 2.2.6的Camel 3.2.0。我在我的类路径中的文件myProperties.properties中有一个属性prop=Hello World。我不必定义Property tySourcesPlaceholderConfigrerSpringCamelContextbean

@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:

您可能正在从Exchange获取您的属性,这可能会导致此问题。自Camel 3.0.0版以来,从交易所获取属性已更改。您可以尝试exchange eProperty("xxx")

 类似资料:
  • 我正在用apache Camel构建一个spring boot应用程序。我想让camel中的DSL监听spring boot启动时的相同端口。 我尝试了这个链接,但如果不使用组件,就无法解析它。我不希望我的路由看起来像,而是希望直接使用jetty Build.Gradle

  • 我目前正在尝试熟悉Servicemix、Camel、CXF等,我的问题与四年前的一些人基本相同:如何将Camel中的BeaninJournal对象转换为消息正文和标题?不幸的是,答案对我帮助不大。正如其中一个答案所提到的:Camel网站上的所有示例都与从CXF向bean发送内容有关。 我在POJO中使用了一个bean代理endpoint,通过 当我在另一端使用另一个beanendpoint,为该接

  • 我正在骆驼中开发一种机制,它将从一个可以是真或假的标志中为消息选择一个endpoint。这是一种节流机制,在我的上游通道被洪水淹没的情况下,它将把消息重新路由到批量摄取endpoint(发送到HDFS)。 最终,我的路线是这样的: 我的ThrottleHelper类的buildEndpoint方法如下所示: 目前,我在类上有一个名为checkStatus()的方法;设置shouldThrottle

  • 我使用这个Camel示例作为参考,并更改了初始化器以扩展,以便可以部署到JBoss EAP6.4。 当它作为SpringBoot应用程序运行时: null 部署到JBoss时: 执行器endpoint均不工作。它们都返回http 404。 这个问题并不是演示所独有的,我们在JBoss中运行的所有容器化Camel Spring Boot应用程序都有同样的问题,并且需要明确的是,这些应用程序的功能完全

  • 没有“org.apache.camel.CamelContext”类型的合格bean可用:应至少有一个合格的自带候选bean。 依赖项注释:{@org.SpringFramework.Beans.Factory.Annotation.AutoWired(required=true)}

  • 我正在使用带有Apache骆驼的Spring Boot。我正在从控制器调用路由。一旦路由完成,控制就会返回控制器。我正在VerifyLimitProcess和批准限制处理器中生成响应。如果我没有在路由中提供窃听配置,控制器会按预期检索标头和正文。但如果我在路由中引入窃听,控制器会将标头和正文接收为null。如果有人指出我需要做什么,以便我可以在选择语句中引入两个处理器的窃听配置,即VerifyLi