我正在使用smooks api进行java-xml和xml-java转换。此代码在jboss4.2.2中工作,但迁移jboss7.1.1得到异常“无法无法访问jboss中的资源数据流7.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>
module.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)
Smooks中的Smooks的Smooks =新的Smooks(resourceURI);它加载访问路径,他们使用InpuStream。 – nag 2013-03-20 17:56:58
是的,但我认为你需要提供InputStream。这很可能是模块(org.milyn)使用'Thread.currentThread()。getContextClassLoader()。getResourceAsStream()'这是行不通的。 – 2013-03-21 01:07:34
默认情况下,smooks正在接受此路径E:\ jboss-as-7.1.1.Final \ bin \ WEB-INF \ smooks-config.xml,我应该如何更改/ WEB-INF/smooks-config的运行时路径。 xml? – nag 2013-03-25 14:42:37