首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法访问柑橘-context.xml中的全局变量

无法访问柑橘-context.xml中的全局变量
EN

Stack Overflow用户
提问于 2018-07-27 19:51:37
回答 1查看 387关注 0票数 0

给定以下citrus-context.xml

代码语言:javascript
复制
<?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,而是得到了以下错误:

代码语言:javascript
复制
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}

这是因为配置问题,还是当前的设置不可能?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-29 19:22:36

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

代码语言:javascript
复制
<context:property-placeholder location="classpath:endpoint.properties"/>

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

代码语言:javascript
复制
<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
              ...">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51564680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档