其實很久以前就已經着手做這個事了,一直沒有突破,後來就放下了。
今天終於花了大半天時間把這個事給基本搞定了。網上沒有找到直接介紹webx集成測試的資料,所幸在部門中引入本框架的同事提醒我可以看看pet-store的例子或許會有答案。正好以前也下載下來了,結果還真找到了。其實就是下面幾行代碼
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:cah2.xml" },
loader = SpringextContextLoader.class)
public class DaoTest extends AbstractTransactionalJUnit4SpringContextTests {
最重要的是指定springext類加載器。原來採用如下常規的spring默認類加載器方式
public class XXC extends AbstractDependencyInjectionSpringContextTests {
protected String[] getConfigLocations() {
return new String[] { "classpath:cah.xml" };
}
只要xml中命名空間<services:使用之處,如<services::property-placeholder>解析時就會報出如下錯誤
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root
element of the document is not <xsd:schema>.
仔細觀察cah.xml,
<?xml version="1.0" encoding="UTF-8" ?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:services="http://www.alibaba.com/schema/services"
xmlns:ml-adapters="http://www.alibaba.com/schema/services/module-loader/adapters"
xmlns:ml-factories="http://www.alibaba.com/schema/services/module-loader/factories"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
http://www.alibaba.com/schema/services/module-loader/adapters http://localhost:8080/schema/services-module-loader-adapters.xsd
http://www.alibaba.com/schema/services/module-loader/factories http://localhost:8080/schema/services-module-loader-factories.xsd
http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
">
<services:property-placeholder>
<services:property key="component">store</services:property>
</services:property-placeholder>
以上schemalocation在xml catalogs中映射的本地路徑都沒有問題.後來通過查看webx提供的petstore例子,發現最大的區別就是指定springext類加載器。
經過修改爲開頭所寫的方式後,命名空間解析找不到schema reference的錯誤消失了。