我有一个Spring Boot应用程序,它使用Apache Camel来定义和控制数据的路由。这些路由是通过XML DSL定义的,并且具有属性占位符,以允许定义的路由的可变性。
当我试图定义和使用一个项目集合时,我得到了一个错误:
Caused by: java.lang.IllegalArgumentException: Property with key [http-client.timers['http-get'].name] not found in properties from text: timer:{{http-client.timers['http-get'].name}}?delay={{http-client.timers['http-get'].start-delay}}&fixedRate=true&period={{http-client.timers['http-get'].period}}&repeatCount={{http-client.timers['http-get'].repeat-count}}application.yml:
---
camel:
springboot:
name: MissionServices
main-run-controller: true
http-client:
server:
host: localhost
port: 9100
endpoint: chars?size=500
timers:
- http-get:
name: http-get
start-delay: 0
period: 1000
repeat-count: 5
- http-post:
name: http-post
start-delay: 0
period: 5000
repeat-count: 5camel-context.xml:
...
<camelContext id="camel-context"
xmlns="http://camel.apache.org/schema/spring">
<route id="http-get">
<from
uri="timer:{{http-client.timers['http-get'].name}}?delay={{http-client.timers['http-get'].start-delay}}&fixedRate=true&period={{http-client.timers['http-get'].period}}&repeatCount={{http-client.timers['http-get'].repeat-count}}" />
<log loggingLevel="INFO" message="start - http-get" />
<setHeader name="HTTP_METHOD">
<constant>GET</constant>
</setHeader>
<to
uri="http:{{http-client.server.host}}:{{http-client.server.port}}/{{http-client.endpoint}}" />
<log loggingLevel="INFO" message="end - http-get" />
</route>
<route id="http-post">
<from uri="direct:start-http-post" />
<log loggingLevel="INFO" message="start - http-post" />
<setHeader name="HTTP_METHOD">
<constant>POST</constant>
</setHeader>
<setHeader name="CONTENT_TYPE">
<constant>application/json</constant>
</setHeader>
<to
uri="http:{{http-client.server.host}}:{{http-client.server.port}}/{{http-client.endpoint}}" />
<log loggingLevel="INFO" message="end - http-post" />
</route>
</camelContext>
...是YAML的结构不正确,还是我在路由定义中使用了错误的语法来访问属性?
发布于 2020-04-08 21:09:52
首先,yml中的缩进是不正确的。
其次,结构不太正确。您正在寻找的是一个对象映射,其中包含字段name、start-delay、period和repeat-count。但您已将其声明为列表。
您正在尝试通过键(http-get)查找对象。您不能使用key搜索列表。你可以用索引搜索列表。你需要的是一张地图。
正确的yaml结构应为
http-client:
server:
host: localhost
port: 9100
endpoint: chars?size=500
timers:
http-get:
name: http-get
start-delay: 0
period: 1000
repeat-count: 5
http-post:
name: http-post
start-delay: 0
period: 5000
repeat-count: 5要访问您正在查找的值,应该如下所示
{{http-client.timers.http-get.name}}发布于 2020-04-08 21:01:45
嗯,http-client.timers['http-get'].name声明name嵌套在http-get中,而您的YAML中:
timers:
- http-get:
name: http-get
start-delay: 0
period: 1000
repeat-count: 5name:是http-get:的兄弟(它们共享相同的缩进级别,有关这种情况下的缩进处理的详细信息,请使用see this answer )。此外,您在这里启动了一个序列(使用-),但是路径没有对序列进行任何索引。你可能想要
timers:
http-get:
name: http-get
start-delay: 0
period: 1000
repeat-count: 5https://stackoverflow.com/questions/61101151
复制相似问题