无法访问 citrus 内部的全局变量-context.xml
Cannot Access Global Variables Inside citrus-context.xml
给出以下 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}
这是配置问题,还是当前设置不可行?
请将 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
...">
给出以下 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}
这是配置问题,还是当前设置不可行?
请将 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
...">