Web Service 自动生成代码报错
案例 1
生成时报错:WSDL file has validation errors. Code generation may fail
启动报错: Caused by: javax.xml.ws.WebServiceException: Unable to create JAXBContext at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158) at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:87) at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:262) at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:322) at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:188) at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467) at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:253) at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147) at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:108) ... 24 more Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions java.util.List is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at java.util.List java.util.List does not have a no-arg default constructor. this problem is related to the following location: at java.util.List
参考:http://jyao.iteye.com/blog/1213655
解决方法:将服务端的services接口返回的Map类型的值,改成HashMap.
结论:在做webServices复杂类型值传递时,返回值的类型不要用接口类型。例如(List应该改为ArrayList,Map改为HashMap,或者用String[]数组等)
案例 2
服务端或客户端生成包时,报错:cannot find the declaration of element 'html'
原因:由于在web.xml配置了struts2的过滤器,代码如:
<!-- 配置Struts2核心过滤器(拦截器) --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
将/*修改为.action或.do,在struts.xml中.action不能访问静态权限,因此不能要:
<!--
该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为false
-->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
而.do必须要:
<!-- 设置url请求后缀 -->
<constant name="struts.action.extension" value="do"></constant>
并且在jsp的表单action中必须加后缀.action或.do
我有两个梦想,一是娶一美丽贤惠的姑娘,二是有一稳定踏实的工作。