weixin_37594473
2017-04-19 09:41
采纳率: 100%
浏览 1.0k
已采纳

首次使用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-20 03:44
    已采纳

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

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • weixin_38388710 2017-04-19 14:49

    可能是jar包冲突。。。。

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题