【问题标题】:Is there a way to set rest configuration headers from property file values?有没有办法从属性文件值设置其余配置头?
【发布时间】:2020-01-03 12:57:30
【问题描述】:

这里我试图从属性文件中访问全局属性并将其设置在其余配置中的 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,并且为每个属性进行更改将是乏味的。有什么解决办法吗?

提前致谢!

【问题讨论】:

    标签: java spring apache-camel spring-camel ava


    【解决方案1】:

    嗯,不确定占位符是否适用于所有标签(包括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}}" /> 
    

    【讨论】:

    • 不,它会在部署时失败,提示错误已发布。
    猜你喜欢
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 2021-12-22
    相关资源
    最近更新 更多