首次使用webservice报错,求解答

代码:import java.util.HashMap;
import java.util.Map;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import net.sf.json.JSON;
import net.sf.json.JSONObject;

@WebService
public class sayhello {
@WebMethod
public JSON add(){
Maptest=new HashMap();
test.put("1", "a1");
test.put("2", "a2");
test.put("3", "a3");
test.put("4", "a4");
test.put("5", "a5");
test.put("6", "a6");
JSONObject jsonObject = JSONObject.fromObject(test);
return jsonObject;
}

public static void main(String[] args) {
    System.out.println(System.getProperty("java.endorsed.dirs"));
    Endpoint.publish("http://localhost:9001/service/sayhello", new sayhello());
    System.out.println("success");
}

}

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/jdk/lib/endorsed/slf4j-jdk14-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/%e7%8e%8b%e8%b4%9d%e8%b4%9d/Workspaces/MyEclipse%208.5/service/WebRoot/WEB-INF/lib/slf4j-jdk14-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
Exception in thread "main" java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:36)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:95)
at javax.xml.ws.spi.Provider.provider(Provider.java:76)
at javax.xml.ws.Endpoint.publish(Endpoint.java:156)
at com.net.cn.sayhello.main(sayhello.java:29)
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle.getBundle(Unknown Source)
at org.apache.cxf.common.i18n.BundleUtils.getBundle(BundleUtils.java:80)
at org.apache.cxf.common.logging.LogUtils.createLogger(LogUtils.java:249)
at org.apache.cxf.common.logging.LogUtils.getL7dLogger(LogUtils.java:201)
at org.apache.cxf.jaxws.spi.ProviderImpl.(ProviderImpl.java:68)
... 10 more

2个回答

图片说明 我改了一下测试是可以的,public JSON add() 返回值改为String,json 就是一个字符串,至于将对象转换为json,推荐用google 的gson 自己动手百度一下很简单的,希望能帮到你!

可能是jar包冲突。。。。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐