当前位置:编程学习 > JAVA >>

spring整合axis,当接口返回List集合时出错

  我目前正在使用axis,是在Servlet环境下使用的。并且应用到Spring框架。现在有一个问题:
  我按照例子编写代码,和配置布署文件。
  1,HelloService
  public interface HelloService {
public List<String> sayHello();
  }
  2, HelloServiceBean
  public class HelloServiceBean implements HelloService {
public List<String> sayHello() {
List<String> strList = new ArrayList<String>();
strList.add("abc");
strList.add("bbc");
strList.add("xxx");
return strList;
}
  }
  3,JaxRpcHelloService(继承Spring的超类)
  public class JaxRpcHelloService extends ServletEndpointSupport implements
HelloService {

public List<String> sayHello() {
HelloService helloService = new HelloServiceBean();
return helloService.sayHello();
}

  }
  4,axis对应的服务布署文件
  <service name="HelloService" provider="java:RPC">
<parameter name="allowedMethods" value="*"></parameter>
<parameter name="className" value="cn.leo.jpetstore.webservice.axis.JaxRpcHelloService">       </parameter>
  </service>
  5,生产客户端的配置文件(clientContext.xml)
  <bean id="jaxRpcProxyHello"
class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean">
<property name="serviceFactoryClass">
<value>org.apache.axis.client.ServiceFactory</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://${serverName}:${httpPort}${contextPath}/axis/HelloService?wsdl
</value>
</property>
<property name="namespaceUri">
<value>http://${serverName}:${httpPort}${contextPath}/axis/HelloService
</value>
</property>
<property name="serviceName">
<value>JaxRpcHelloServiceService</value>
</property>
<property name="portName">
<value>HelloService</value>
</property>
<property name="serviceInterface">
<value>cn.leo.jpetstore.webservice.HelloService</value>
</property>
<!-- If you want to work with a JAX-RPC port stub underneath, you need 
to specify an RMI interface to use at the JAX-RPC port level. This might 
give advantages on certain JAX-RPC implementations. If not specified, JAX-RPC 
dynamic calls will be used, which has been tested to work nicely on Apache 
Axis. -->
<!-- <property name="portInterface"> <value>org.springframework.samples.jpetstore.service.RemoteOrderService</value> 
</property> -->
  </bean>
  6,测试用例
  ApplicationContext ctx = new ClassPathXmlApplicationContext(
"clientContext.xml");
  HelloService service = (HelloService) ctx.getBean("jaxRpcProxyHello");
  List<String> list = service.sayHello();
  报如下错误:java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.List
at $Proxy5.sayHello(Unknown Source)
at cn.leo.jpetstore.webservice.HelloServiceTest.test(HelloServiceTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  7,服务的发布是没有问题的,我也在网上查了很多资料,但是一直没有搞明白。当方法返回单个对象时没有任何问题,现在我个人认为有两个问题点:1,是如何对布署文件进行正确配置。2,是clientContext.xml配置文件还没有配置完全。但是苦于个人水平与时间的限制,没有进一步去研究源码,所以请高手帮忙解答。 --------------------编程问答-------------------- 有个替换方案,不返回List,返回数组 --------------------编程问答-------------------- 你返回的object数组,怎么能当list数组使用,转化下

List<Object[]> temp = (List<Object[]>) query.list();
List<WorkList> list = new ArrayList<WorkList>();
WorkList workList = null;
for (Object[] obj : temp) {
workList = new WorkList();
if (obj[1] != null) {
workList.setObjname(String.valueOf(obj[1]));
}

……
}
}

补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,