2014-05-01 70 views
1

我是web服務和glassfish的新手。這裏是我的代碼Glassfish 4.0加載應用程序時出現異常java.lang.IllegalStateException

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服務。

不能部署TestGF部署失敗=部署過程中出現錯誤:異常 同時加載應用程序:java.lang.IllegalStateException:ContainerBase.addChild:啓動: 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)

回答

4

的問題是,你的方法返回類型是一個接口,並且JAXB不能與接口一起工作,因爲它不知道要使用哪個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 

這應該指出你在正確的方向,如果類似的錯誤發生。

參見:

+0

感謝。我將列表更改爲ArrayList。它部署OK。但是當我運行時,響應似乎返回一個空對象。我看到的全是。但是,如果我拿走RPC風格,我會看到返回的列表爲你好 user2125853

相關問題