gpt4 book ai didi

web-services - Glassfish 4.0 加载应用程序时出现异常,java.lang.IllegalStateException

转载 作者:行者123 更新时间:2023-12-01 23:23:08 25 4
gpt4 key购买 nike

我是网络服务和 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";
}
}

如果我有

@SOAPBinding(style=Style.RPC)

当我尝试部署 Web 服务时,出现以下错误。

cannot Deploy TestGF deploy is failing=Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: Servlet web service endpoint '' failure. Please see server.log for more details.

服务器日志没有更多内容。

当我注释掉@SOAPBinding(style=Style.RPC)时,它部署得很好

问题似乎出在第一种方法上。如果我排除第一种方法,则第二种方法可以正常部署。当我从方法返回列表并且我有 @SOAPBinding(style=Style.RPC)

时,我似乎遇到了这个问题

我正在使用 Glassfish 4.0、jdk 1.7 和 Eclipse(与 Spring 3.4 捆绑在一起)

最佳答案

问题是您的方法返回类型是一个接口(interface),而 JAXB 无法使用接口(interface),因为它不知道要使用哪个 List 实现。

要修复它,只需将方法的返回类型更改为 ArrayList,如下所示:

public ArrayList<String> testRPC () {
ArrayList<String> l = new ArrayList<String>();
l.add("Hello");
return l;
}

正如错误消息所示,可以在 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

如果出现类似错误,这应该会为您指明正确的方向。

另请参阅:

关于web-services - Glassfish 4.0 加载应用程序时出现异常,java.lang.IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23413036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com