为什么我不能导入Mule配置文件?

时间:2014-01-13 15:30:51

标签: spring import mule

我有这个简单的配置文件:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:test="http://www.mulesoft.org/schema/mule/test" version="EE-3.4.1" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.2/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.2/mule-jms.xsd
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/3.2/mule-test.xsd">

    <spring:import resource="dataSources.xml"/>

    <jdbc-ee:connector name="apiJDBCConnector" dataSource-ref="apiLogDataSource"> 
        <jdbc-ee:query key="commitAPILogEntries" value="insert into APILogEntries
            (requestName, parameters, serviceParameters, partnerID, partnerIP, statusCode, responseLength, time)
            values
            (#[map-payload:REQUEST_NAME], #[map-payload:PARAMETERS], #[map-payload:SERVICE_PARAMETERS], #[map-payload:PARTNER_ID]::int, inet(#[map-payload:PARTNER_IP]), #[map-payload:STATUS_CODE]::int, #[map-payload:RESPONSE_LENGTH]::int, TIMESTAMP WITHOUT TIME ZONE 'epoch' + #[map-payload:TIMESTAMP]::bigint * INTERVAL '1 millisecond')"></jdbc-ee:query>  
    </jdbc-ee:connector>

</mule>

我在这里要做的是在单独的配置文件中定义数据源,然后在其他地方使用这些数据源。但是,我一直在dataSource-ref元素上出错,而​​Mule拒绝运行。

dataSources.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<spring:beans>

    <spring:bean id="apiLogDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <spring:property name="driverClassName" value="${jdbc.driverClassName}"/>
        <spring:property name="url" value="${jdbc.apilog.url}"/>
        <spring:property name="username" value="${jdbc.apilog.username}"/>
        <spring:property name="password" value="${jdbc.apilog.password}"/>
    </spring:bean>    

</spring:beans>

我做错了什么,因为我无法让它发挥作用?

1 个答案:

答案 0 :(得分:1)

您的单独配置仍需要包含在mule根元素中,并具有所需的命名空间等,以使其正常工作。例如:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
   <spring:beans>

       <spring:bean id="apiLogDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
          <spring:property name="driverClassName" value="${jdbc.driverClassName}"/>
          <spring:property name="url" value="${jdbc.apilog.url}"/>
          <spring:property name="username" value="${jdbc.apilog.username}"/>
          <spring:property name="password" value="${jdbc.apilog.password}"/>
       </spring:bean>    

   </spring:beans>
</mule>

仅供参考:即使在此之后MuleStudio可能会抱怨它无法找到“apiLogDataSource”,但它运行正常。