java - 有没有办法从属性文件值设置其余配置 header ?

标签 java spring apache-camel spring-camel ava

在这里,我尝试从属性文件访问全局属性,并将其设置在其余配置的enableCORS header 中,例如

<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: Attribute 'prop:enableCORS' is not allowed to appear in element '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}}" /> 

关于java - 有没有办法从属性文件值设置其余配置 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59579051/

相关文章:

java - Togglz:java.lang.IllegalStateException:找不到FeatureManager

java - 使用 Spring 配置 Hazelcast 的正确方法

java - 当没有通过 -P 指定配置文件时,执行什么 Maven 配置文件?

jdbc项目中的java.lang.NumberFormatException

java - 关于 JtaTransactionManager 的问题

java - 从路线外停止 Camel 路线

java - Camel - 从 url 获取 xml

xpath - Apache Camel/xpath 操作结果检测

java - 将所有文件下载为 zip

java - Activity 及其 Fragment 的单个布局文件和单个 java 文件