Apache camel 属性值不可访问

Apache camel 属性值不可访问,apache-camel,spring-camel,Apache Camel,Spring Camel,我是骆驼的初学者。我有一些问题 我们正在使用camel实现文件传输系统 我从外部属性文件设置属性 但应用程序无法访问此属性文件。我们无法使用propertyplaceholder,因为该值将在运行时更改 我们实现了它,如下所示 camelContext.xml: 错误日志: 如果要使用properties组件,需要将名称与属性绑定,如下所示 <camelContext trace="{{foo.trace}}" xmlns="http://camel.apache.org/schema/s

我是骆驼的初学者。我有一些问题

我们正在使用camel实现文件传输系统

我从外部属性文件设置属性

但应用程序无法访问此属性文件。我们无法使用propertyplaceholder,因为该值将在运行时更改

我们实现了它,如下所示

camelContext.xml:

错误日志:


如果要使用properties组件,需要将名称与属性绑定,如下所示

<camelContext trace="{{foo.trace}}" xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder id="properties" location="org/apache/camel/spring/processor/myprop.properties"/>
    <template id="camelTemplate" defaultEndpoint="{{foo.cool}}"/>
    <route>
        <from uri="direct:start"/>
        <setHeader headerName="{{foo.header}}">
            <simple>${in.body} World!</simple>
        </setHeader>
        <to uri="mock:result"/>
    </route>
</camelContext>
你可以找到更多信息


不确定您是否正在使用spring boot,有一种简单的方法可以在Camel中利用spring boot。

您是否尝试将camelap.properties放置在src/main/resources或src/test/resources中?谢谢您的评论。但是我想使用Property,而不是propertyPlaceholder,因为我读过一些文章,在运行时使用Property可以改变属性值,但是使用propertyPlaceholder不能改变值。我想知道如何使用属性标记绑定属性。谢谢。PropertyPlaceHolder帮助我们解析property组件的值。该示例帮助您修复异常。如果在端点uri上使用属性,则仅在解析端点时才接受属性值。
path : target/classes
file.uri=/home/WRK/KR/SND/DAT
test=OLD_VALUE
file.pattern=SLPNPM*,SPLNCC*,SLPNCM*,SLPNPC*

############################################
## SQL Statement ##
############################################
sql.referenceInfo=SELECT DISTINCT \
                        A.WFLOW_INST_ID ,\
                        TO_CHAR(A.EFCT_ST_DT,'YYYYMMDDHH24MISS') EFCT_ST_DT, \
                        B.NE_ID , \
                        B.NE_TYPE_ID , \
                        B.CDR_FILE_COLEC_DIR_NM , \
                        B.ORIGIN_FMT_ID , \
                        B.TRM_DIR_NM , \
                        D.CDR_FILE_NMNG_RULE_SBST, \
                        D.FILE_NM_LEN , \
                        B.FNS_FILE_CRET_YN , \
                        B.FNS_FILE_DIV_CD \
                        FROM TB_WFLOW_INFO A, \
                            TB_CDRSEND_BASE_INFO B, \
                            TB_FILE_FMT_INFO D \
                        WHERE A.WFLOW_INST_ID = 'P1_IPTVKR' \
                        AND B.NE_ID = 'KRLPPM10' \
                        AND now() BETWEEN A.EFCT_ST_DT AND A.EXP_DT \
                        AND now() BETWEEN B.EFCT_ST_DT AND B.EXP_DT \
                        AND A.WFLOW_INST_ID = B.WFLOW_INST_ID \
                        AND B.ORIGIN_FMT_ID = D.CDR_FILE_FMT_ID;
   org.apache.camel.RuntimeCamelException:
   org.apache.camel.FailedToCreateRouteException: Failed to create route initial_info at: >>> To[sql:{{sql.referenceInfo}}?dataSource=dataSource] <<< in route: Route(initial_info)[[From[direct:sqlParam]] -> [To[sql:{{sql... because of Property with key [sql.referenceInfo] not found in properties from text: sql:{{sql.referenceInfo}}?dataSource=dataSource
       at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1826) ~[camel-core-2.23.1.jar:2.23.1]
       at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) ~[camel-spring-2.23.1.jar:2.23.1]
       at org.apache.camel.spring.CamelContextFactoryBean.start(CamelContextFactoryBean.java:370) ~[camel-spring-2.23.1.jar:2.23.1]
       at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:417) ~[camel-spring-2.23.1.jar:2.23.1]
       at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:95) ~[camel-spring-2.23.1.jar:2.23.1]
       at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:896) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
       at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
       at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
       at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
  at com.ktds.openmzn.OpenmznApplication.main(OpenmznApplication.java:25) ~[classes/:na]
  .....
  Caused by: java.lang.IllegalArgumentException: Property with key [sql.referenceInfo] not found in properties from text: sql:{{sql.referenceInfo}}?dataSource=dataSource
  at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.getPropertyValue(DefaultPropertiesParser.java:271) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.readProperty(DefaultPropertiesParser.java:157) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.doParse(DefaultPropertiesParser.java:116) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.parse(DefaultPropertiesParser.java:100) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.component.properties.DefaultPropertiesParser.parseUri(DefaultPropertiesParser.java:63) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:235) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:178) ~[camel-core-2.23.1.jar:2.23.1]
  at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:2547) ~[camel-core-2.23.1.jar:2.23.1]
<camelContext trace="{{foo.trace}}" xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder id="properties" location="org/apache/camel/spring/processor/myprop.properties"/>
    <template id="camelTemplate" defaultEndpoint="{{foo.cool}}"/>
    <route>
        <from uri="direct:start"/>
        <setHeader headerName="{{foo.header}}">
            <simple>${in.body} World!</simple>
        </setHeader>
        <to uri="mock:result"/>
    </route>
</camelContext>