当我尝试启动这个简单的 Web 服务时,我是 JAX-WS 的新手:
界面:
package ws;
import java.util.HashMap;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface IBasket {
@WebMethod public abstract void addItem(int productId, int count);
@WebMethod public abstract HashMap<Integer, Integer> getBasketMap();
}
实现类:
package model;
import java.util.HashMap;
import javax.jws.WebService;
import ws.IBasket;
@WebService(endpointInterface = "ws.IBasket")
public class Basket implements IBasket {
private HashMap<Integer, Integer> basket;
public Basket() {
this.basket = new HashMap<Integer, Integer>();
}
@Override
public void addItem(int productId, int count) {
int currentCount = 0;
if (basket.containsKey(productId)) {
currentCount = basket.get(productId);
}
basket.put(productId, currentCount + count);
}
@Override
public HashMap<Integer, Integer> getBasketMap() {
return basket;
}
}
出版商:
package endpoint;
import javax.xml.ws.Endpoint;
import model.Basket;
public class WSPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/WS/Basket",new Basket());
}
}
我得到以下堆栈跟踪:
Exception in thread "main" javax.xml.ws.WebServiceException: class ws.jaxws.GetBasketMapResponse do not have a property of the name return
at com.sun.xml.internal.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:196)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.createResponseMessageBuilder(EndpointMethodHandler.java:191)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.<init>(EndpointMethodHandler.java:97)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.<init>(SEIInvokerTube.java:72)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:208)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:498)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:246)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:170)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:113)
at javax.xml.ws.Endpoint.publish(Endpoint.java:240)
at endpoint.WSPublisher.main(WSPublisher.java:14)
Caused by: javax.xml.bind.JAXBException: return is not a valid property on class ws.jaxws.GetBasketMapResponse
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:966)
at com.sun.xml.internal.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:193)
... 10 more
任何想法如何解决这个问题?