java - 有没有办法从属性文件值设置其余配置头?
问题描述
在这里,我试图从属性文件中访问全局属性并将其设置在其余配置中的 enableCORS 标头中,例如
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:prop="http://camel.apache.org/schema/placeholder"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring" streamCache="true" id="service-v1.0.0">
<propertyPlaceholder id="a-properties" location="classpath:model.properties" xmlns="http://camel.apache.org/schema/spring" />
<restConfiguration component="servlet" bindingMode="auto" prop:enableCORS="cors-header-enabled" />
</camelContext>
但是当我这样做时。我收到一个错误,例如
cvc-complex-type.3.2.2:属性“prop:enableCORS”不允许出现在元素“restConfiguration”中
我该如何设置以及我应该改变什么才能使其工作。
就我而言,将有许多服务 xml,并且为每个属性进行更改将是乏味的。有什么解决方法吗?
提前致谢!
解决方案
嗯,不确定占位符是否适用于所有标签(包括restConfiguration)
医生说:
The property placeholders is also supported in *many* of the Camel
Spring XML tags such as <package>, <packageScan>, <contextScan>,
<jmxAgent>, <endpoint>, <routeBuilder>, <proxy> and the others.
也许你可以尝试替代语法?
<restConfiguration ... enableCORS="{{cors-header-enabled}}" />
推荐阅读
- reactjs - 当每个表单的结构都可以更改时,如何将表单类型数据传递给表单 HOC?
- python - 当 self 在同一范围/功能中预先引用时,self 仅在 eval 范围内
- angular - Angular 8 BehaviorSubject 无法更改所需的值
- flutter - How to change Font style in Html widget in Flutter?
- python - 如何在 tkinter 中加载屏幕?
- lua - Lua函数在给定数字时获得不同的数据类型
- php - 给定对象列表的PHP按键查找值
- javascript - 传递属性以反应组件为空
- flutter - 选择单选按钮到主屏幕后如何从警报对话框传递数据
- excel - 通过 Excel 2019 中的工作表内的按钮激活宏需要更多时间来执行