一个简单的cxf Webservice,可是报 NullPointerException 异常 10
接口类:importjavax.jws.WebMethod;importjavax.jws.WebService;@WebServicepublicinterfaceHe...
接口类:
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface HelloService {
@WebMethod
String sayHi(String name);
}
实现类:
/**
*
* @author Administrator
*/
@WebService(endpointInterface = "com.yhb.service.HelloService")
public class HelloServiceImpl implements HelloService {
public String sayHi(String name) {
return name + " hello~!";
}
}
服务类:
import org.apache.cxf.frontend.ServerFactoryBean;
public class MainServer {
protected MainServer() throws Exception {
HelloServiceImpl helloworldImpl = new HelloServiceImpl();
ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.setServiceClass(HelloService.class);
svrFactory.setAddress("http://127.0.0.1:8080/cxfDemo/Hello");
svrFactory.setServiceBean(helloworldImpl);
svrFactory.create();
}
public static void main(String args[]) throws Exception {
new MainServer();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
}
可是一运行MainServer的main() 时,就报
Exception in thread "main" java.lang.NullPointerException
at org.apache.cxf.jaxb.JAXBDataBinding.createContext(JAXBDataBinding.java:566)
at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:504)
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:324)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:442)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:505)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:242)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:148)
,其他的在配置文件里,我也没有写什么。
图片为 我添加的jar包。
希望各位大虾帮帮忙,小弟正在学习cxf中。要是有和spring集成的,完整示例的,可以发到我的邮箱:pyptyhb.184sxd@163.com 展开
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface HelloService {
@WebMethod
String sayHi(String name);
}
实现类:
/**
*
* @author Administrator
*/
@WebService(endpointInterface = "com.yhb.service.HelloService")
public class HelloServiceImpl implements HelloService {
public String sayHi(String name) {
return name + " hello~!";
}
}
服务类:
import org.apache.cxf.frontend.ServerFactoryBean;
public class MainServer {
protected MainServer() throws Exception {
HelloServiceImpl helloworldImpl = new HelloServiceImpl();
ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.setServiceClass(HelloService.class);
svrFactory.setAddress("http://127.0.0.1:8080/cxfDemo/Hello");
svrFactory.setServiceBean(helloworldImpl);
svrFactory.create();
}
public static void main(String args[]) throws Exception {
new MainServer();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
}
可是一运行MainServer的main() 时,就报
Exception in thread "main" java.lang.NullPointerException
at org.apache.cxf.jaxb.JAXBDataBinding.createContext(JAXBDataBinding.java:566)
at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:504)
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:324)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:442)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:505)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:242)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:148)
,其他的在配置文件里,我也没有写什么。
图片为 我添加的jar包。
希望各位大虾帮帮忙,小弟正在学习cxf中。要是有和spring集成的,完整示例的,可以发到我的邮箱:pyptyhb.184sxd@163.com 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询