如何将属性从多个属性占位符注入到java中(How to inject properties from multiple property placeholders into java)

编程入门 行业动态 更新时间:2024-10-24 20:22:02
如何将属性从多个属性占位符注入到java中(How to inject properties from multiple property placeholders into java)

在我的camel / blueprint项目中,我在blueprint.xml中定义了一个property-placeholder :

<cm:property-placeholder id="props.placeholder" persistent-id="props.blueprint"> <cm:default-properties> <cm:property name="app.name" value="app-service" /> </cm:default-properties> </cm:property-placeholder>

有了这个,我可以在java中注入属性(例如驼峰路线):

@Value("${app.name}") private String name;

现在我需要引入第二个属性占位符:

<cm:property-placeholder id="container_specific.placeholder" persistent-id="container_specific.blueprint" placeholder-prefix="%%{" placeholder-suffix="}%%"> <cm:default-properties> <cm:property name="service.port" value="1234"/> </cm:default-properties> </cm:property-placeholder>

但是如何使用/注入第二个持有者的属性到java? @Value("%%{service.port}%%)不起作用。

In my camel/blueprint project i defined a property-placeholder in the blueprint.xml:

<cm:property-placeholder id="props.placeholder" persistent-id="props.blueprint"> <cm:default-properties> <cm:property name="app.name" value="app-service" /> </cm:default-properties> </cm:property-placeholder>

With this in place i can inject the properties in java (e.g. camel routes):

@Value("${app.name}") private String name;

Now i need to introduce a 2nd property placeholder:

<cm:property-placeholder id="container_specific.placeholder" persistent-id="container_specific.blueprint" placeholder-prefix="%%{" placeholder-suffix="}%%"> <cm:default-properties> <cm:property name="service.port" value="1234"/> </cm:default-properties> </cm:property-placeholder>

But how to use/inject property from the 2nd holder into java? @Value("%%{service.port}%%) does not work.

最满意答案

阅读文档: http : //camel.apache.org/using-propertyplaceholder.html

有一个示例显示如何通过id引用蓝图,因此只需配置Camel以引用这两个ID

<propertyPlaceholder id="properties" location="blueprint:props.placeholder,blueprint:container_specific.placeholder">

Read the documentation: http://camel.apache.org/using-propertyplaceholder.html

There is an example which shows how to refer to the blueprint by id, so just configure Camel to refer to those two ids

<propertyPlaceholder id="properties" location="blueprint:props.placeholder,blueprint:container_specific.placeholder">

更多推荐

本文发布于:2023-04-29 02:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   多个   如何将   java   inject

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!