我正在使用 smooks api 进行 java-xml 和 xml-java 转换。此代码在 jboss4.2.2 中工作,但迁移 jboss7.1.1 时出现异常是“无法访问资源数据流”
示例代码:
private String runSmooksTransform(Object inputJavaObject)
throws IOException, SAXException {
Smooks smooks = new Smooks("/WEB-INF/smooks-config.xml");
try {
ExecutionContext executionContext = smooks.createExecutionContext();
StringWriter writer = new StringWriter();
smooks.filterSource(executionContext,
new org.milyn.payload.JavaSource(inputJavaObject),
new StreamResult(writer));
return writer.toString();
} finally {
smooks.close();
}
}
smooks-config.xml
<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd" >
<resource-config selector="global-parameters">
<param name="stream.filter.type">SAX</param>
</resource-config>
</smooks-resource-list>
模块.xml
<module xmlns="urn:jboss:module:1.1" name="org.milyn">
<resources>
<resource-root path="milyn-smooks-all-1.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="org.apache.commons.logging" />
<module name="org.jaxen" />
<module name="org.hibernate" slot="3" />
</dependencies>
</module>
例外 :
java.io.IOException: Failed to access data stream for resource [/WEB-INF/smooks-config.xml]. Tried (in order):
10:10:14,113 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) File System: E:\WEB-INF\smooks-config.xml
10:10:14,114 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) File System: E:\jboss-as-7.1.1.Final\bin\WEB-INF\smooks-config.xml
10:10:14,117 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) Classpath: /WEB-INF/smooks-config.xml
10:10:14,125 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)
10:10:14,126 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.milyn.resource.URIResourceLocator.getResource(URIResourceLocator.java:130)
10:10:14,128 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.milyn.resource.URIResourceLocator.getResource(URIResourceLocator.java:84)
10:10:14,129 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.milyn.Smooks.addConfigurations(Smooks.java:307)
10:10:14,131 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.milyn.Smooks.<init>(Smooks.java:151)
10:10:14,133 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at com.manam.mobee.customer.MobeeCustomerHome.runSmooksTransform(MobeeCustomerHome.java:644)