weixin_37594473 2017-04-19 01:41 采纳率: 100%
浏览 1030
已采纳

首次使用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条回答 默认 最新

  • 阿蓝好多个8 2017-04-19 19:44
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部