无法访问citrus-context.xml

时间:2018-07-27 19:51:37

标签: citrus-framework

给出以下citrus-context.xml

<?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:citrus="http://www.citrusframework.org/schema/config"
    xmlns:citrus-http="http://www.citrusframework.org/schema/http/config"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd
       http://www.citrusframework.org/schema/http/config http://www.citrusframework.org/schema/http/config/citrus-http-config.xsd">

    <citrus:global-variables>
        <citrus:file
            path="classpath:endpoints.properties" />
    </citrus:global-variables>

    <citrus-http:client
        id="service_endpoint"
        request-url="${Service.Endpoint.URL}"
        request-method="GET"
        content-type="text/xml"
        charset="UTF-8"
        timeout="60000" />
</beans>

我没有得到${Service.Endpoint.URL}http://foo.io/service的评估,而是得到了以下错误:

com.consol.citrus.exceptions.TestCaseFailedException: Illegal character in path at index 1: ${Service.Endpoint.URL}
...
Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 1: ${Service.Endpoint.URL}
...
Caused by: java.net.URISyntaxException: Illegal character in path at index 1: ${Service.Endpoint.URL}

是因为配置问题,还是无法进行当前设置?

1 个答案:

答案 0 :(得分:0)

请在您的应用程序上下文中添加一个Spring属性占位符配置器。配置器能够评估Spring bean定义中的属性表达式。在应用程序上下文中解析Spring bean时,在设计时不考虑Citrus全局变量。

<context:property-placeholder location="classpath:endpoint.properties"/>

属性占位符正在使用特殊的context: Spring bean名称空间。因此,您需要在配置文件中声明此命名空间:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:citrus="http://www.citrusframework.org/schema/config"
   xmlns:context="http://www.springframework.org/schema/context"
   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
              ...">