use*_*853 2 web-services glassfish
我是网络服务和玻璃鱼的新手.这是我的代码
package ws.mypkg;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style=Style.RPC)
public class TestRPC {
// This seems to cause the problem when a List is returned.
public List<String> testRPC () {
List<String> l = new ArrayList<String>();
l.add("Hello");
return l;
}
// This method work fine
public String testRPC1 () {
return "Testing RPC";
}
}
Run Code Online (Sandbox Code Playgroud)
如果我有
@SOAPBinding(style=Style.RPC)
Run Code Online (Sandbox Code Playgroud)
我尝试部署Web服务时收到以下错误.
无法部署TestGF部署失败=部署期间发生错误:加载应用程序时出现异常:java.lang.IllegalStateException:ContainerBase.addChild:start:org.apache.catalina.LifecycleException:java.lang.RuntimeException:Servlet Web服务端点''失败.有关更多详细信息,请参阅server.log.
服务器日志没有更多.
当我发表评论时,它会部署得很好 @SOAPBinding(style=Style.RPC)
问题似乎与第一种方法有关.如果我排除第一个方法,第二个方法部署正常.当我从方法中返回一个列表时,我似乎遇到了这个问题@SOAPBinding(style=Style.RPC)
我正在使用Glassfish 4.0,jdk 1.7和Eclipse(与Spring 3.4捆绑在一起)
问题是您的方法返回类型是一个接口,JAXB不能使用接口,因为它不知道List要使用哪个实现.
要修复它,只需将方法的返回类型更改为ArrayList:
public ArrayList<String> testRPC () {
ArrayList<String> l = new ArrayList<String>();
l.add("Hello");
return l;
}
Run Code Online (Sandbox Code Playgroud)
正如错误消息所示,可以在中找到更多信息server.log.应该有类似的东西:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 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
Run Code Online (Sandbox Code Playgroud)
如果发生类似错误,这应该指向正确的方向.
也可以看看:
| 归档时间: |
|
| 查看次数: |
9341 次 |
| 最近记录: |