Apache Camel - 使用spring从属性文件中读取JDBC dataSource属性

时间:2018-03-18 14:23:09

标签: java spring apache-camel

我需要从属性文件

加载数据源属性

db.properties:

url = my_url
user = user_name
password = user_pass

这是dataSource(camelcontext.xml):

我这样尝试,它不起作用。

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:db.properties"/>  </bean>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
  <property name="URL" value="${url}"/>
  <property name="user" value="${user}"/>
  <property name="password" value="${pasword}"/>
</bean> 

我的路由是在java dsl。

中实现的

3 个答案:

答案 0 :(得分:0)

url = my_url property name =“URL”value =“$ {url}”

答案 1 :(得分:0)

使用像${...}这样的表达式语言时,您必须引用属性文件的键,而不是值。你可能想写s.th.像

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
  <property name="URL" value="${url}"/>
  <property name="user" value="${user}"/>
  <property name="password" value="${password}"/>
</bean> 

答案 2 :(得分:0)

为了在Spring XML中使用Camel Properties,你必须添加以下Spring bean以及ID&#39;属性&#39;

<bean id="properties"
    class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="location" value="classpath:db.properties"/>
</bean>

或(在您发表评论后请尝试此操作):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
       <property name="URL" value="${url}"/>
       <property name="user" value="${user}"/>
       <property name="password" value="${pasword}"/>
    </bean> 

    <context:property-placeholder properties-ref="properties"/>
    <util:properties id="properties" location="classpath:db.properties"/>